在Angular Js中滚动1次后无限滚动两次?

时间:2019-03-12 07:50:04

标签: angularjs infinite-scroll

我已经实现了无限滚动进出网站,但是在1次滚动后会触发两次。我使用了无限滚动禁用功能,但对我不起作用。告诉我有人如何解决滚动问题?

  $scope.loadMore = function() {
    $scope.infiniteScorllStatus  = true;
     $scope.adv_offset ++;

    if($scope.infiniteScorllStatus) {
       $http.get(APP.service.userPost + 
            '?user_id=' + $rootScope.currentUserID + '&limit=' +  $scope.limit + '&offset=' +  $scope.offset +  '&adv_offset=' + $scope.adv_offset).then(function(response) {
        if(response.data.status == 1) {

          //
          $scope.shots =  response.data.response;
          $scope.offset =  $scope.shots.length;
          $scope.limit = $scope.offset + 6;
          $scope.infiniteScorllStatus  = false; 
        }
      });
    }
}


<div infinite-scroll="loadMore()" infinite-scroll-distance="0" 
     infinite-scroll-disabled="infiniteScorllStatus" >
    <section class=" masonry-item" ng-repeat="item in data">
      {{item.name}}
    </section>
 </div>

我已经尝试了上面的代码,但是它对我不起作用,告诉我代码中有什么问题吗?

1 个答案:

答案 0 :(得分:0)

如果$ scope.infiniteScorllStatus为true,则从函数返回。

 $scope.loadMore = function() {
    if ( $scope.infiniteScorllStatus)
        return;
    $scope.infiniteScorllStatus  = true;
     $scope.adv_offset ++;

    if($scope.infiniteScorllStatus) {
       $http.get(APP.service.userPost + 
            '?user_id=' + $rootScope.currentUserID + '&limit=' +  $scope.limit + '&offset=' +  $scope.offset +  '&adv_offset=' + $scope.adv_offset).then(function(response) {
        $scope.infiniteScorllStatus  = false; 
        if(response.data.status == 1) {

          //
          $scope.shots =  response.data.response;
          $scope.offset =  $scope.shots.length;
          $scope.limit = $scope.offset + 6;

        }
      });
    }
}