Javascript AngularJS-在两个容器内滚动-anchorScroll
我有一个固定高度的两列页面。每列中的项目重复 如何在每列中滚动到某个id?AngularJS有可能吗 代码Javascript AngularJS-在两个容器内滚动-anchorScroll,javascript,angularjs,Javascript,Angularjs,我有一个固定高度的两列页面。每列中的项目重复 如何在每列中滚动到某个id?AngularJS有可能吗 代码 滚动到一个位置 第#列: 项目#: 第一栏 {{$index}}。。。。。{{item}} 第二栏 {{$index}}。。。。。{{item}} JS: app.controller('myCtrl',['$scope',函数($scope){ $scope.value='test'; $scope.itemsOne=[]; $scope.itemsTwo=[]; 对于(var i
滚动到一个位置
第#列:
项目#:
第一栏
{{$index}}。。。。。{{item}}
第二栏
{{$index}}。。。。。{{item}}
JS:
app.controller('myCtrl',['$scope',函数($scope){
$scope.value='test';
$scope.itemsOne=[];
$scope.itemsTwo=[];
对于(var i=0;i我更改了您的plunkr以使其工作,有很大的改进空间,但请注意,当您需要在DOM中处理事情时,必须始终使用指令,就像我所做的那样:
app.directive('autoScrollTo', function () {
return function(scope, element, attrs) {
scope.$watch(attrs.autoScrollTo, function(value) {
if (value) {
var pos = $("#" +attrs.prefixId +value, $(element)).position().top + $(element).scrollTop() - $(element).position().top;
$(element).animate({
scrollTop : pos
}, 1000);
}
});
}
});
看到它在运行:
希望能有所帮助。我更改了您的plunkr以使其正常工作,还有很多改进的余地,但请注意,当您需要在DOM中处理事情时,必须始终使用指令,就像我所做的那样:
app.directive('autoScrollTo', function () {
return function(scope, element, attrs) {
scope.$watch(attrs.autoScrollTo, function(value) {
if (value) {
var pos = $("#" +attrs.prefixId +value, $(element)).position().top + $(element).scrollTop() - $(element).position().top;
$(element).animate({
scrollTop : pos
}, 1000);
}
});
}
});
看到它在运行:
希望这会有帮助。真棒的回答,和我希望的一样,非常感谢。我希望用像anchorScroll这样的东西来做这件事,但这也很好。真棒的回答,和我希望的一样,非常感谢。我希望用像anchorScroll这样的东西来做,但这也很好。
app.directive('autoScrollTo', function () {
return function(scope, element, attrs) {
scope.$watch(attrs.autoScrollTo, function(value) {
if (value) {
var pos = $("#" +attrs.prefixId +value, $(element)).position().top + $(element).scrollTop() - $(element).position().top;
$(element).animate({
scrollTop : pos
}, 1000);
}
});
}
});