当我在用ng-repeat创建的元素下降时,如何向下滚动

How to scroll down when i descend in the elements created with ng-repeat

本文关键字:滚动 元素 ng-repeat 创建      更新时间:2023-09-26

我有一个用ng-repeat创建的列表和两个向上或向下的按钮。用户可以选择列表中的任何元素,并使用两个按钮向上或向下移动。

当按钮向下移动选定元素时,滚动条仍然固定,我无法再看到选定的元素。

我想在元素被隐藏时向下滚动

        <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();
    }
};