我面临的问题是,角度无限滚动在移动设备上不起作用-在小米Redmi Note 4和三星Galaxy 4上进行了测试。


  我的代码可在PC和IOS设备上正常工作。


问题仅在移动设备上再现。

也许有人遇到同样的问题?你能建议我一些吗?

$scope.loadNews = function() {
  if ($scope.position > $scope.allNews.length) return;
  if ($scope.allNews.length > $scope.news.length) {
    var partOfNews = $scope.getPartOfEntities($scope.newsPosition, $scope.scrollNewsCount, 0);
    for (var i = 0; i < partOfNews.length; i++) {
      $scope.news.push(partOfNews[i]);
    }
  }
};


<div ng-hide="showSpinner">

  <div infinite-scroll='loadNews()' infinite-scroll-distance='0.5'>
    <hr>
    <news data="news"></news>

  </div>

</div>






        handler = function() {
          var elementBottom, remaining, shouldScroll, windowBottom;
          windowBottom = $window.height() + $window.scrollTop();
          elementBottom = elem.offset().top + elem.height();
          remaining = elementBottom - windowBottom;
          shouldScroll = remaining <= $window.height() * scrollDistance;
          if (shouldScroll && scrollEnabled) {
            if ($rootScope.$$phase) {
              return scope.$eval(attrs.infiniteScroll);
            } else {
              return scope.$apply(attrs.infiniteScroll);
            }
          } else if (shouldScroll) {
            return checkWhenEnabled = true;
          }
        };

          var applied = false;
          var touchmover = function () {
              if ( ! applied) {
                  applied = true;
                  $window.on('touchend', handler);
              }
          };

          $window.on('touchmove', handler);
          scope.$on('$destroy', function() {
              $window.off('touchend', handler);
              applied = false;
              return $window.off('touchmove', touchmover);
        });

最佳答案

您可以使用基于滚动的简单代码

$('#news').bind('scroll', function(){ if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight){ //alert(1); loadNews(); } });

关于javascript - 为什么ngInfiniteScroll(无限滚动)在移动设备上不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42951988/

10-13 09:13