$ionicScrollDelegate.anchorScroll() does not work reliably
Previous issue: https://github.com/driftyco/ionic/issues/508
The anchorscroll functionality does not work reliably. Check out this Plunkr: http://plnkr.co/edit/4bPK01zF0e0euJetZbxD?p=preview
I see two issues:
- Anchor elements can not be wrapped in another element. In the Plunkr I have wrapped div id="day2" into another div. Jumping to that link does not work.
- After clicking one or two times all anchor links won't work anymore.
Issue 2 is fixed when using the setTimeout function on scroll-content in the scroll function:
$scope.gotoDay = function(id){ $location.hash(id); console.log($location.hash()); $ionicScrollDelegate.anchorScroll(true); setTimeout(function() { document.querySelector('.scroll-content').scrollTop = 0; }, 0); }
Issue 1 remains:
- Anchor elements can not be wrapped in another element.
Checking this out now, thanks for the research Coen.
@CoenWarmer, could you paste this over your getPositionInParent function and lemme know how it works in your app? It fixes the test in the plnkr you posted, and some other tests I did.
getPositionInParent: function(el, parentEl) {
return { left: el.offsetLeft, top: el.offsetTop };
},
Yup, that works! Thank you!
this really works for me : http://www.saintsatplay.com/blog/2015/02/scrolling-to-a-page-anchor-in-ionic-framework#.VcvVmPmqqko
I can get the scrolling to work well enough, but it isn't consistently scrolling to the same spot. Sometimes it scrolls a little higher and then a second click will scroll to the right spot. A third will go to the higher location again.
My anchors are nested, which I'm guessing is a contributing factor.
document.getElementById(eId).scrollIntoView(); works consistently.
Any thoughts?