我有一个用ng-repeat创建的列表和两个按钮上升或下降。用户可以选择列表中的任何元素,然后使用两个按钮向上或向下。
当我按下按钮下降所选元素时,滚动条仍然固定,我不能再看到所选元素。
我希望在元素隐藏时向下移动滚动。
答案 0 :(得分:0)
<div class="panel-body panelBodySelectedData" style="padding-left: 10px">
<nav>
<ul ng-repeat="item in resultJson.items" class="nav nav-pills nav-stacked span2">
<li class="itemReporting" ng-click="selectItem($index)" ng-class="{selectedReportingItem: $index==selectedIndex}" >{{item.label}}</li>
</ul>
</nav>
</div>
$scope.goUp = function(){
if($scope.selectedIndex > 0){
console.log('goUp');
$scope.aux = $scope.resultJson.items[$scope.selectedIndex];
$scope.selectedIndex -- ;
$scope.resultJson.items[$scope.selectedIndex+1] = $scope.resultJson.items[$scope.selectedIndex];
$scope.resultJson.items[$scope.selectedIndex] = $scope.aux;
}
};
$scope.goDown = function(){
if($scope.selectedIndex < $scope.resultJson.items.length -1){
console.log('goDown');
$scope.aux = $scope.resultJson.items[$scope.selectedIndex];
$scope.selectedIndex ++ ;
$scope.resultJson.items[$scope.selectedIndex-1] = $scope.resultJson.items[$scope.selectedIndex];
$scope.resultJson.items[$scope.selectedIndex] = $scope.aux;
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
}
};