Best way to preload images with Angular.js

前端 未结 9 883
野性不改
野性不改 2020-12-07 16:04

Angular\'s ng-src keeps previous model until it preloads image internally. I am using different image for the banner on each page, when I switch routes, i change main view,

9条回答
  •  感情败类
    2020-12-07 16:42

    Instead of using

    element.on('load', function() {});
    

    use imagesLoaded plugin. It will speed up dramatically your images.

    So the final code would be:

    link: function(scope, element) {
      imagesLoaded(element, function() {
    
      });
      scope.$watch('ngSrc', function() {
    
      });
    }
    

提交回复
热议问题