fix(scroll): anchor scroll should scroll to IDs that are multiple levels beneath the scroll view. Closes #1804

This commit is contained in:
Perry Govier
2014-07-21 14:58:29 -05:00
parent 5b50e120a1
commit 3d0a46efe8
2 changed files with 48 additions and 5 deletions

View File

@@ -146,12 +146,19 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
this.resize().then(function() {
var hash = $location.hash();
var elm = hash && $document[0].getElementById(hash);
if (hash && elm) {
var scroll = ionic.DomUtil.getPositionInParent(elm, self.$element);
scrollView.scrollTo(scroll.left, scroll.top, !!shouldAnimate);
} else {
if (!(hash && elm)) {
scrollView.scrollTo(0,0, !!shouldAnimate);
return;
}
var curElm = elm;
var scrollLeft = 0, scrollTop = 0, levelsClimbed = 0;
do {
if(curElm !== null)scrollLeft += curElm.offsetLeft;
if(curElm !== null)scrollTop += curElm.offsetTop;
curElm = curElm.offsetParent;
levelsClimbed++;
} while (curElm.attributes != self.element.attributes && curElm.offsetParent !== null);
scrollView.scrollTo(scrollLeft, scrollTop, !!shouldAnimate);
});
};