EVOLUTION-MANAGER
Edit File: $anchorScroll.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/anchorScroll.js?message=docs($anchorScroll)%3A%20describe%20your%20change...#L32' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ng/anchorScroll.js#L32' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">$anchorScroll</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> <a href="api/ng/provider/$anchorScrollProvider">- $anchorScrollProvider</a> </li> <li> - service in module <a href="api/ng">ng</a> </li> </ol> </header> <div class="api-profile-description"> <p>When called, it checks the current value of <a href="api/ng/service/$location#hash">$location.hash()</a> and scrolls to the related element, according to the rules specified in the <a href="http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document">Html5 spec</a>.</p> <p>It also watches the <a href="api/ng/service/$location#hash">$location.hash()</a> and automatically scrolls to match any anchor whenever it changes. This can be disabled by calling <a href="api/ng/provider/$anchorScrollProvider#disableAutoScrolling">$anchorScrollProvider.disableAutoScrolling()</a>.</p> <p>Additionally, you can use its <a href="api/ng/service/$anchorScroll#yOffset">yOffset</a> property to specify a vertical scroll-offset (either fixed or dynamic).</p> </div> <div> <h2 id="dependencies">Dependencies</h2> <ul> <li><a href="api/ng/service/$window"><code>$window</code></a></li><li><a href="api/ng/service/$location"><code>$location</code></a></li><li><a href="api/ng/service/$rootScope"><code>$rootScope</code></a></li> </ul> <h2 id="usage">Usage</h2> <p><code>$anchorScroll();</code></p> <h2>Properties</h2> <ul class="properties"> <li id="yOffset"> <h3><code>yOffset</code></h3> <table class="variables-matrix return-arguments"> <tr> <td><a href="" class="label type-hint type-hint-number">number</a><a href="" class="label type-hint type-hint-function">function()</a><a href="" class="label type-hint type-hint-jqlite">jqLite</a></td> <td><p>If set, specifies a vertical scroll-offset. This is often useful when there are fixed positioned elements at the top of the page, such as navbars, headers etc.</p> <p><code>yOffset</code> can be specified in various ways:</p> <ul> <li><strong>number</strong>: A fixed number of pixels to be used as offset.<br /><br /></li> <li><strong>function</strong>: A getter function called everytime <code>$anchorScroll()</code> is executed. Must return a number representing the offset (in pixels).<br /><br /></li> <li><strong>jqLite</strong>: A jqLite/jQuery element to be used for specifying the offset. The distance from the top of the page to the element's bottom will be used as offset.<br /> <strong>Note</strong>: The element will be taken into account only as long as its <code>position</code> is set to <code>fixed</code>. This option is useful, when dealing with responsive navbars/headers that adjust their height and/or positioning according to the viewport's size.</li> </ul> <p><br /></p> <div class="alert alert-warning"> In order for <code>yOffset</code> to work properly, scrolling should take place on the document's root and not some child element. </div></td> </tr> </table> </li> </ul> <h2 id="example">Example</h2><p> <div> <a ng-click="openPlunkr('examples/example-example48')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example48" module="anchorScrollExample"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><div id="scrollArea" ng-controller="ScrollController"> <a ng-click="gotoBottom()">Go to bottom</a> <a id="bottom"></a> You're at the bottom! </div></code></pre> </div> <div class="runnable-example-file" name="script.js" language="js" type="js"> <pre><code>angular.module('anchorScrollExample', []) .controller('ScrollController', ['$scope', '$location', '$anchorScroll', function ($scope, $location, $anchorScroll) { $scope.gotoBottom = function() { // set the location.hash to the id of // the element you wish to scroll to. $location.hash('bottom'); // call $anchorScroll() $anchorScroll(); }; }]);</code></pre> </div> <div class="runnable-example-file" name="style.css" language="css" type="css"> <pre><code>#scrollArea { height: 280px; overflow: auto; } #bottom { display: block; margin-top: 2000px; }</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example48/index.html" name="example-example48"></iframe> </div> </div> </p> <p><hr /> The example below illustrates the use of a vertical scroll-offset (specified as a fixed value). See <a href="api/ng/service/$anchorScroll#yOffset">$anchorScroll.yOffset</a> for more details.</p> <p> <div> <a ng-click="openPlunkr('examples/example-example49')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example49" module="anchorScrollOffsetExample"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><div class="fixed-header" ng-controller="headerCtrl"> <a href="" ng-click="gotoAnchor(x)" ng-repeat="x in [1,2,3,4,5]"> Go to anchor {{x}} </a> </div> <div id="anchor{{x}}" class="anchor" ng-repeat="x in [1,2,3,4,5]"> Anchor {{x}} of 5 </div></code></pre> </div> <div class="runnable-example-file" name="script.js" language="js" type="js"> <pre><code>angular.module('anchorScrollOffsetExample', []) .run(['$anchorScroll', function($anchorScroll) { $anchorScroll.yOffset = 50; // always scroll by 50 extra pixels }]) .controller('headerCtrl', ['$anchorScroll', '$location', '$scope', function ($anchorScroll, $location, $scope) { $scope.gotoAnchor = function(x) { var newHash = 'anchor' + x; if ($location.hash() !== newHash) { // set the $location.hash to `newHash` and // $anchorScroll will automatically scroll to it $location.hash('anchor' + x); } else { // call $anchorScroll() explicitly, // since $location.hash hasn't changed $anchorScroll(); } }; } ]);</code></pre> </div> <div class="runnable-example-file" name="style.css" language="css" type="css"> <pre><code>body { padding-top: 50px; } .anchor { border: 2px dashed DarkOrchid; padding: 10px 10px 200px 10px; } .fixed-header { background-color: rgba(0, 0, 0, 0.2); height: 50px; position: fixed; top: 0; left: 0; right: 0; } .fixed-header > a { display: inline-block; margin: 5px 15px; }</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example49/index.html" name="example-example49"></iframe> </div> </div> </p> </div>