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

Angular should provide a way to scroll to a specific element on the page #114

Closed
esprehn opened this issue Nov 1, 2010 · 10 comments
Closed

Angular should provide a way to scroll to a specific element on the page #114

esprehn opened this issue Nov 1, 2010 · 10 comments

Comments

@esprehn
Copy link
Contributor

@esprehn esprehn commented Nov 1, 2010

Fragment identifiers (hash) are usually used to link to specific places in a long page. This doesn't work with angular since the hash is being used to implement the route. A way to scroll down the page to a specific element should be provided.

@vojtajina
Copy link
Contributor

@vojtajina vojtajina commented Oct 13, 2011

Yep, and then, we should use it with $location - as now, we support hash as well, so whenever $location.hash() changes, we should scroll to it...

@IgorMinar
Copy link
Contributor

@IgorMinar IgorMinar commented Apr 2, 2012

This was already implemented. If $location operates in html5 mode then just create href="#anchor" links

@IgorMinar IgorMinar closed this Apr 2, 2012
@gabrielstuff
Copy link

@gabrielstuff gabrielstuff commented Jan 6, 2013

Sorry to bump on that, but what if we are not in html5 mode ? see this two fidle for references :
http://jsfiddle.net/gabrielstuff/SdGnR/ which use the router and breaks the anchor linking.
and this one
http://jsfiddle.net/gabrielstuff/nYxFg/ which is not using any router and correctly allow to jump along the same page.

Also not the trying with HTML5 did not help much (but this is an other ticket)

@stryderjzw
Copy link

@stryderjzw stryderjzw commented Jan 28, 2013

I have the same problem. I'm not in html5 mode. How would this work in hashbang mode?

@chrisnicola
Copy link
Contributor

@chrisnicola chrisnicola commented Jun 11, 2013

I agree this behavior is very unexpected. Even if someone is not using HTML5 mode Angular shouldn't break this expected behaviour when using a hash with an anchor.

As I understand it, Angular should just simply ignore any links with explicit hashes in them anyways. If we aren't using HTML5 the link <a href="/something"... will automatically get rewritten as /#/something (unless I target _self). So <a href="#something" should arguably always go to /#something

@nc
Copy link

@nc nc commented Oct 6, 2013

+1

@cironunes
Copy link
Member

@cironunes cironunes commented Oct 6, 2013

I think you should use anchorScroll to do that.

@chrisnicola
Copy link
Contributor

@chrisnicola chrisnicola commented Oct 6, 2013

Just curious @IgorMinar could we get a comment on whether or not this issue is going to be fixed? One could argue that it doesn't need to be on the basis of outdated browsers not being fully supported but I think a clear answer on whether or not anchor links should work with browsers that don't support the history API.

I get the problem though, if I'm at #/route1 then it's hard to be at #/route1#anchor. The hack mentioned here (http://www.benlesh.com/2013/02/angular-js-scrolling-to-element-by-id.html) seems ok, but it would be ideal if this "just worked". Anyways if the $anchorScroll hack is the solution then it might be good to say that and perhaps someone can update the documentation to reflect how this problem should be solved for older browsers.

@lekhnath
Copy link

@lekhnath lekhnath commented Mar 24, 2015

Here ( http://stackoverflow.com/a/15935517/2071612) is a brilliant solution.

@gkalpak
Copy link
Member

@gkalpak gkalpak commented Mar 24, 2015

BTW, I have submitted a PR (#9596) for adding support for scrolling independently of $location.hash().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants