img load必须用load(this),不能用load(eImg) 似乎eImg在回调时已经不是页面上那个对象
function fillPicture(elementId,picArrays){
if(!picArrays)return;
var iPictures=document.getElementById(elementId),
piclen=picArrays.length;
iPictures.innerHTML=""
for (var i = 0; i < piclen; i++) {
var eImg=new Image();
//eImg.addEventListener('load',function(){imgLoaded(eImg)},false);
eImg.className="span3";
eImg.src=picArrays[i];
eImg.οnlοad=function(){imgLoaded(this)};//!!!!imgLoaded(eImg)导致后面无法操纵页面元素
iPictures.appendChild(eImg);
};
}
function imgLoaded(img){
if (img.complete) {
callback(img);
} else {
setTimeout(function(){callback(img)},500);
};
}
function callback(img){
resizeImg(img);
}
//resize images
function resizeImg(obj) {
console.log(obj)
console.log('width:' + obj.naturalWidth+' height:' + obj.naturalHeight);
$(obj).removeClass("span3");//!!!!imgLoaded(eImg)导致这里无效
if(obj.naturalWidth>270 ){
var ratio=obj.naturalWidth/obj.naturalHeight;
if(ratio<=3){
obj.className="span3";
}//free the too broad picature
}
}