javascript - 当我下降到使用 ng-repeat 创建的元素时如何向下滚动

标签 javascript css angularjs scroll scrollbar

我有一个使用 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();

    }
};

关于javascript - 当我下降到使用 ng-repeat 创建的元素时如何向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33144190/

相关文章:

javascript - 单击一个对象并显示另一个对象 - 简单的 jQuery 片段

javascript - 如何在javascript中重新定义私有(private)方法?

javascript - Angular 动态地将 ng-messages 设置为 name 属性

javascript - json 与对象中的比较

javascript - 使用 JavaScript 更改光标

javascript - 如何为过滤结果选择更多复选框值?

html - 无法水平居中div

css - 仅使用 CSS 淡出后隐藏元素

javascript - 将宽度设置为最宽的元素,同时仍然有 float

javascript - AngularJS 服务函数调用另一个函数