页面顶部有一个锚点:
<a href="#top">Logo goes here</a>
在页面的底部,有一个联系人表单。我想跳转到页面的顶部,完成联系表单后的锚。
$location.path("#top")
无济于事。
该怎么做呢?
发布于 2015-01-23 10:01:45
用棱角分明的方式。使用$anchorScroll
手册页面中的示例正是您想要的,只是它滚动到底部而不是顶部……
发布于 2015-01-28 14:28:13
$anchorScroll就是这样做的。
var myApp = angular.module('myApp', []);
myApp.controller('myController', function ($scope, $location, $anchorScroll) {
$scope.gotoBottom = function(myTarget) { // this is the function to call with ng-click
$location.hash(myTarget); // set the target
$anchorScroll(); // scroll to the target that has been set
};
}]);
然后您将拥有如下所示的HTML:
<div ng-controller="myController">
<a ng-click="gotoBottom('goHere')">Scroll to my target location</a>
<p>Some random stuff</p>
<p>Some random stuff</p>
<p>Some random stuff</p>
<a id="goHere">This is where you scroll to</a>
</div>
https://stackoverflow.com/questions/28107243
复制