angularjs - ng-repeat 中渐进式加载图像、Angular JS

标签 angularjs lazy-loading angularjs-ng-repeat progressive

如何在向下滚动页面时实现内容的渐进式加载?否则会同时加载 1000 张图像。

最佳答案

使用无限滚动指令。 ngInfiniteScroll

DEMO

<小时/>

HTML

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

JS

var myApp = angular.module('myApp', ['infinite-scroll']);
myApp.controller('DemoController', function($scope) {
  $scope.images = [1, 2, 3, 4, 5, 6, 7, 8];

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

关于angularjs - ng-repeat 中渐进式加载图像、Angular JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18204473/

相关文章:

angularjs - 在 angularjs 中使用 debounce 延迟代码

angularjs - 如何对 ui-bootstrap $uibModal 实例的结果进行单元测试?

reactjs - Nextjs 检查初始渲染是否在服务器端完成

javascript - AngularJs多级数据钻取

javascript - AngularJS ng-bind-html 不呈现列表标签

javascript - 从延迟加载文件延迟加载时出错 - angular.js

android - android中的图片懒加载

c# - Unity 容器 - 延迟注入(inject)

javascript - ng-repeat 过滤器不适用于引号

javascript - Angular 动态选择具有相互影响的项目