有人能解释一下$anchorScroll,偏移,scrollX,scrollY在Components中的用法吗?
发布于 2018-02-16 14:03:35
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();
};
}]);这是正式文件给出的例子。
它将$anchorScroll服务注入控制器。一旦您完成将$location哈希设置为所需位置的id (例如,要滚动到的元素开始),就可以通过$anchorScroll()调用它来使用该服务。
如果您不愿意将$location服务注入控制器,那么最好直接将元素的id传递给$anchorScroll('bottom')。
如果页面顶部有一个固定的导航条(或沿行的内容),则需要指定要添加到滚动位置的偏移量(否则,一旦滚动完成,导航将覆盖元素)。为此,请将其设置为$anchorScroll.yOffset = 100。
发布于 2017-03-29 06:08:16
尝试使用AngularJS文档来获取它。
https://stackoverflow.com/questions/43084254
复制相似问题