How do I implement progressive loading of content as you scroll down the page? Otherwise 1000 images would load at the same time.
Progressive loading in ng-repeat for images, angular js
39.3k views Asked by TheNickyYo At
2
There are 2 answers
2
On
Use infinite scrolling directive. ngInfiniteScroll
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);
}
};
});
I didn't want to use
ngInfiniteScroll
the other guy posted as my mobile app does not use jQuery so there is no point in loading it just for this.Anyhow, I found a jsfiddle with pure Javascript that solves this problem.
HTML
JavaScript
Source: http://jsfiddle.net/vojtajina/U7Bz9/