Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

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

Comments

@esprehn
Copy link
Contributor

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

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

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

@gabrielstuff
Copy link

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

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

@chrisnicola
Copy link
Contributor

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 commented Oct 6, 2013

+1

@cironunes
Copy link
Member

I think you should use anchorScroll to do that.

@chrisnicola
Copy link
Contributor

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

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

@gkalpak
Copy link
Member

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants