ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

$ionicScrollDelegate.anchorScroll() does not work reliably

Open CoenWarmer opened this issue 12 years ago • 6 comments

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.

CoenWarmer avatar Feb 17 '14 11:02 CoenWarmer

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.

CoenWarmer avatar Feb 17 '14 12:02 CoenWarmer

Checking this out now, thanks for the research Coen.

ajoslin avatar Feb 17 '14 13:02 ajoslin

@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 };
  },

ajoslin avatar Feb 17 '14 14:02 ajoslin

Yup, that works! Thank you!

CoenWarmer avatar Feb 17 '14 14:02 CoenWarmer

this really works for me : http://www.saintsatplay.com/blog/2015/02/scrolling-to-a-page-anchor-in-ionic-framework#.VcvVmPmqqko

amrography avatar Aug 12 '15 23:08 amrography

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?

MrWiLofDoom avatar Aug 13 '15 18:08 MrWiLofDoom