图片预加载

2018-07-11  本文已影响0人  guoss
 function imgList(){
        var el=[];
        for(var i=0;i<26;i++){
          if(i<10){
              i='0'+i;
          }
          el.push('img/star/0' + i + '.jpg');
        }  
        return el; 
 }
  var imgList = imgList().map(function(ele){
      var img = new Image();
      img.onload = function(){
        leftNum--;
        if(leftNum === 0){
          $(document).trigger('my-imgloaded');
        }
      };
      img.onerror = function(){
        leftNum--;
        if(leftNum === 0){
          $(document).trigger('my-imgloaded');
        }
      };
      img.src = ele;
      return img;
 }); 
$(document).on('my-imgloaded', function(){
    $('.top-bg').removeClass('top-brfore');
    $('.top-bg').addClass('animate');
});

上一篇下一篇

猜你喜欢

热点阅读