Javascript 如何使用anchorscroll()将窗口滚动到AngularJS中的元素?
我正在尝试在AngularJS中对ng click事件实现一个scrollTo效果 我试图滚动到categoryhead,如下所示:Javascript 如何使用anchorscroll()将窗口滚动到AngularJS中的元素?,javascript,angularjs,Javascript,Angularjs,我正在尝试在AngularJS中对ng click事件实现一个scrollTo效果 我试图滚动到categoryhead,如下所示: myApp.controller('FoodCtrl', function ($scope, $http, $location, $anchorScroll) { //other stuff $scope.loadFood = function(category) { //other stuff //Scroll category head to t
myApp.controller('FoodCtrl', function ($scope, $http, $location, $anchorScroll) {
//other stuff
$scope.loadFood = function(category) {
//other stuff
//Scroll category head to top of page
$scope.categoryhead = "#" + category;
$location.hash($scope.categoryhead);
$anchorScroll();
//Ajax load stuff
};
});
我在模板中打印了$scope.categoryhead的值,可以看到它是每个元素的正确ID,但是窗口没有滚动。尝试将元素ID传递给$anchorscroll()时是否出错
您错过了要应用的css,因此没有给出任何高度,因此没有显示滚动条
.scroll{
height: 350px;
overflow: auto;
}
这是更新后的在一段时间后找到的。我错误地指定了
$scope.categoryhead
否,原稿不依赖于上的高度和溢出设置。滚动。如果移除它们,它仍然有效。