Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ionicScrollDelegate.anchorScroll() does not work reliably #618

Closed
CoenWarmer opened this issue Feb 17, 2014 · 6 comments
Closed

$ionicScrollDelegate.anchorScroll() does not work reliably #618

CoenWarmer opened this issue Feb 17, 2014 · 6 comments
Milestone

Comments

@CoenWarmer
Copy link

Previous issue: #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
Copy link
Author

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.

@ajoslin
Copy link
Contributor

ajoslin commented Feb 17, 2014

Checking this out now, thanks for the research Coen.

@ajoslin
Copy link
Contributor

ajoslin commented Feb 17, 2014

@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 added a commit that referenced this issue Feb 17, 2014
Before it, only cancelled scrollTop the first time the hash was set.

Addresses #618
@CoenWarmer
Copy link
Author

Yup, that works! Thank you!

@amrography
Copy link

@MrWiLofDoom
Copy link

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?

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants