zoukankan      html  css  js  c++  java
  • 图片分步加载(解决图片load函数刷新不加载问题)

    /**
    * 高清图加载完成替换模糊图
    * @param showImg 高清图类名 图片一定要有dataindex属性
    * */
    function loadImgHighDefinition(showImg){
    var imgdefereds=[];
    var showImgObj = "." + showImg;
    $(showImgObj).each(function(){
    var dfd=$.Deferred();
    $(this).bind('load',function(){
    var _this = $(this);
    var newoBGiMG = showImg + _this.attr('dataindex');
    console.log(newoBGiMG)
    $('.'+newoBGiMG).attr('src',_this.attr('src'));
    _this.removeClass(showImg);
    dfd.resolve();
    }).bind('error',function(){
    //图片加载错误,加入错误处理
    // dfd.resolve();
    })
    if(this.complete) setTimeout(function(){
    dfd.resolve();
    },500);
    imgdefereds.push(dfd);
    })
    $.when.apply(null,imgdefereds).done(function(){
    callback();
    });
    function callback(){
    $(showImgObj).each(function(){
    var _this = $(this);
    var newoBGiMG = showImg + _this.attr('dataindex');
    $('.'+newoBGiMG).attr('src',_this.attr('src'));
    _this.removeClass(showImg);
    });
    }
    }

  • 相关阅读:
    TCP三次握手与四次挥手
    centos7快捷键
    关于学习简单讲解的个人观点
    继承与派生
    python封装
    python之面向对象编程
    python之re模块
    python之hashlib、suprocess模块
    python之shelve、xml、configparser模块
    python之json、pickle模块
  • 原文地址:https://www.cnblogs.com/xiaomixia/p/8677007.html
Copyright © 2011-2022 走看看