©
Dieses Dokument verwendetPHP-Handbuch für chinesische WebsitesFreigeben
When called, it checks current value of$location.hash()
and scrolls to the related element, according to rules specified in Html5 spec.
It also watches the$location.hash()
and scrolls whenever it changes to match any anchor. This can be disabled by calling$anchorScrollProvider.disableAutoScrolling()
.
$window
$location
$rootScope
$anchorScroll();
id="scrollArea"ng-controller="ScrollController">ng-click="gotoBottom()">Go to bottomid="bottom">You're at the bottom!
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();};}]);
#scrollArea {height:350px;overflow:auto;}#bottom {display:block;margin-top:2000px;}