AngularJS: How to preload images at first page start in angularjs -
i have json object images urls , display images ng-repeat
. problem images flickering when page loaded first time. display preloader (css spinner) , preload images , apply ng-repeat
.
-> plnkr
easy doing while using angular-easy-image-preloader in demo plnkr.
view
<div class="gallery" ng-controller="gallerycontroller"> <img ng-if="loaded" class="appear" ng-repeat="picture in pictures" ng-src="{{picture}}" alt=""> <div ng-if="!loaded"> <div id="preloader-overlay"> <div id="preloader"></div> </div> </div> </div>
angularjs controller
/* gallery controller */ app.controller('gallerycontroller', function( $scope, $timeout, preloader ) { $scope.loaded = false; $scope.pictures = [ "http://www.d3d.sk/images/mk2_granade_full.png", "http://www.d3d.sk/images/aberry-logo.jpg", "http://www.d3d.sk/images/logo-aberry.png", "http://www.d3d.sk/images/crystal_balls.jpg", "http://www.d3d.sk/images/purple_sun.jpg", "http://www.d3d.sk/images/planets.jpg", "http://www.d3d.sk/images/d3d.jpg", "http://www.d3d.sk/images/bpg-logo.png", "http://www.d3d.sk/images/logo - bukona.jpg", "http://www.d3d.sk/images/sky_up_fire.jpg", "http://www.d3d.sk/images/plexus.jpg", "http://www.d3d.sk/images/dch.jpg", "http://www.d3d.sk/images/dimonsium-front-a.jpg", "http://www.d3d.sk/images/dwts-3.jpg", "http://www.d3d.sk/images/dwts-redesign-1.png", "http://www.d3d.sk/images/diplom.jpg", "http://www.d3d.sk/images/genessis.jpg", "http://www.d3d.sk/images/genessis - logo-final.jpg", "http://www.d3d.sk/images/genessis - logo.jpg", "http://www.d3d.sk/images/goholor.jpg", "http://www.d3d.sk/images/iron.jpg", "http://www.d3d.sk/images/bg_body3.jpg", "http://www.d3d.sk/images/bg_body4.jpg", "http://www.d3d.sk/images/lampa-2.png", "http://www.d3d.sk/images/maxenergy-design.jpg", "http://www.d3d.sk/images/north-first-2.jpg", "http://www.d3d.sk/images/north side dres - ver 1c.jpg", "http://www.d3d.sk/images/oznamko-16.jpg", "http://www.d3d.sk/images/oznamko-17.jpg", "http://www.d3d.sk/images/verzia4e.jpg", "http://www.d3d.sk/images/svk-dres.jpg", "http://www.d3d.sk/images/rool-up04bc.jpg", "http://www.d3d.sk/images/senica-letak-maly.jpg", "http://www.d3d.sk/images/merkur - dizajn - 4.jpg", "http://www.d3d.sk/images/trades-world-2.jpg", "http://www.d3d.sk/images/web-1.jpg", "http://www.d3d.sk/images/web-3.jpg", "http://www.d3d.sk/images/web-5.jpg", "http://www.d3d.sk/images/web-7.jpg", "http://www.d3d.sk/images/web-8.jpg", "http://www.d3d.sk/images/web-10.jpg", "http://www.d3d.sk/images/web-11.jpg", "http://www.d3d.sk/images/vizitka.jpg" ]; preloader.preloadimages($scope.pictures).then(function() { $scope.loaded = true; },function() { console.log('failed'); // loading failed on @ least 1 image. }); });
Comments
Post a Comment