0

When using AngularJS, how can I cause the browser's viewport to jump to an element on the same page?

Without AngularJS, the following

<a href="#heading">Go to Heading</a>

<h2 id="heading">Heading</h2>

will cause the browser's viewport to jump to the heading if the link is clicked.

How can I make this work when using AngularJS?

Chen-Tsu Lin
  • 22,876
  • 16
  • 53
  • 63
Ben
  • 15,938
  • 19
  • 92
  • 138

1 Answers1

0

Here is a plugin for that called ngScrollTo;
you can try something like this;

<a scroll-to="section1">Go to Section 1</a>

<div id="section1">Section 1</div>

<a scroll-to="">Go to Top</a> </pre>

http://ngmodules.org/modules/ngScrollTo
And here is the working example;

http://jsfiddle.net/8Mtxc/1/

Idrees Khan
  • 7,702
  • 18
  • 63
  • 111