我已经使用AngularJS设置了一个网站,并且不需要使用路由,因此未实现。我希望能够基于锚点跳至页面中的某个位置,因此我在导航栏中设置了一个链接:
<a href="/services#/myAnchor">Jump to anchor</a>
我放的更远:
<a name="/myAnchor">
但这是行不通的,它必须与AngularJS有关,但是由于我没有使用路由,所以我不知道它是什么。我尝试只使用不带/的#myAnchor,但无论如何,当页面加载时Angular似乎会将其放入,并且无论如何都无法正常工作。
任何想法如何使页面锚点变得基本正常才能再次工作?
您正在寻找$ anchorScroll:
<div id="scrollArea" ng-controller="ScrollController">
<a ng-click="gotoBottom()">Go to bottom</a>
<a id="bottom"></a> You're at the bottom!
</div>
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();
};
}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句