mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(scroll): anchor scroll should scroll to IDs that are multiple levels beneath the scroll view. Closes #1804
This commit is contained in:
15
js/angular/controller/scrollController.js
vendored
15
js/angular/controller/scrollController.js
vendored
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user