判断图片加载完成的JS操作

来源:互联网 发布:淘宝雀氏纸尿裤代理 编辑:程序博客网 时间:2024/04/30 22:03
var a = {  init:function(){      this.initDom();      this.handleImg();  },  initDom:function(){    this.time_img;    this.isLoad = true;     },  doSomething:function(){},  isImgLoad: function (callback) {        var _self = this;        $('.lp-left img').each(function(index,element){            if($(element).height() === 0){                _self.isLoad = false;                return false;            }        });        if(_self.isLoad){            clearTimeout(_self.time_img);            callback();        }else{            _self.isLoad = true;            _self.time_img = setTimeout(function(){                _self.isImgLoad(callback);            },500);        }    },    handleImg: function(){        var _self = this;        _self.isImgLoad(_self.doSomething);    }};

这个兼容性什么的比较好,当然JQ的load()函数也是可以的~~~

0 0
原创粉丝点击