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

Commit e7cfa5c

Browse files
benleshpetebacondarwin
authored andcommitted
docs($anchorScroll): provide an example of basic usage.
Per a request made by Peter Bacon Darwin here: http://www.benlesh.com/2013/02/angular-js-scrolling-to-element-by-id.html?showComment=1370941217879#c8718313084813008967
1 parent 2a3212a commit e7cfa5c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/ng/anchorScroll.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,36 @@
1010
* according to rules specified in
1111
* {@link http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document Html5 spec}.
1212
*
13-
* It also watches the `$location.hash()` and scroll whenever it changes to match any anchor.
13+
* It also watches the `$location.hash()` and scrolls whenever it changes to match any anchor.
1414
* This can be disabled by calling `$anchorScrollProvider.disableAutoScrolling()`.
15+
*
16+
* @example
17+
<example>
18+
<file name="index.html">
19+
<div ng-controller="MainCtrl">
20+
<a ng-click="gotoBottom()">Go to bottom</a>
21+
<a id="bottom"></a> You're at the bottom!
22+
</div>
23+
</file>
24+
<file name="script.js">
25+
function ScrollCtrl($scope, $location, $anchorScroll) {
26+
$scope.gotoBottom = function (){
27+
// set the location.hash to the id of
28+
// the element you wish to scroll to.
29+
$location.hash('bottom');
30+
31+
// call $anchorScroll()
32+
$anchorScroll();
33+
}
34+
}
35+
</file>
36+
<file name="style.css">
37+
#bottom {
38+
display: block;
39+
margin-top: 2000px;
40+
}
41+
</file>
42+
</example>
1543
*/
1644
function $AnchorScrollProvider() {
1745

0 commit comments

Comments
 (0)