loadPicSize:function(sourceSrc){ console.log(sourceSrc); var self =this; this.preLoadImg(sourceSrc,function(){ self.popupPic.attr("src",sourceSrc); console.log("self.popupPic:"+self.popupPic); var picWidth =self.popupPic.width(); var picHeight=self.popupPic.height(); console.log("picWidth:"+picWidth); console.log("picHeight:"+picHeight); }); }, preLoadImg:function(src,callback){ var img=new Image(); if(!!window.ActiveXObject){ img.onreadystatechange=function(){ if (this.readyState=="complete") { callback(); }; }; }else { img.onload=function(){ callback(); }; }; img.src=src; },
代码如上,报错如下
这个问题卡了好久求解答!
找到原因了,困扰了我半天,在模板加载那个函数的img 没加 class,如下:
'<img class="lightbox-images" src="./images/1-2.jpg" alt="">'+
以为没class,一直回去不了 $("img.lightbox-images
")这个对象!