3
<div >
<div infinite-scroll='loadMore()' infinite-scroll-distance='2'>
    <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'>
</div>

$scope.images = [1, 2, 3, 4, 5, 6, 7, 8];

    $scope.loadMore = function () {
        console.log('scroll');
        var last = $scope.images[$scope.images.length - 1];
        for (var i = 1; i <= 30; i++) {
            $scope.images.push(last + i);
        }
    };

loadMore 函数只在我进入页面时开始调用,向下滚动后不再调用该方法,这是为什么呢?

4

2 回答 2

0
<div infinite-scroll="functionName()" infinite-scroll-distance="1" infinite-scroll-container="'#yourContainer'" > 

转到开发人员工具并找到您需要无限滚动的容器并命名容器。

有关文档,请检查链接 http://sroze.github.io/ngInfiniteScroll/documentation.html

于 2018-01-04T08:52:43.047 回答
0

如果初始页面加载未填满视口高度,则不会调用 loadMore 函数。添加infinite-scroll-immediate-check="true" - 这将强制在页面加载时填充项目。

修改代码

<div>
    <div infinite-scroll='loadMore()' 
         infinite-scroll-distance='2' 
         infinite-scroll-immediate-check="true">
        <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'>
    </div>
</div>

参考无限滚动立即检查

于 2015-08-18T11:43:38.603 回答