jQuery有没有获取图片实际尺寸的方法?
就是图片文件的实际尺寸,而不是添加了css样式之后的尺寸。
肥肠真实,如假包换!
//code from http://caibaojian.com/jquery-get-img-width-height.html$(function(){ var imgSrc = $("#image").attr("src"); getImageWidth(imgSrc,function(w,h){ console.log({width:w,height:h});
});
});function getImageWidth(url,callback){ var img = new Image();
img.src = url;
// 如果图片被缓存,则直接返回缓存数据
if(img.complete){
callback(img.width, img.height);
}else{ // 完全加载完毕的事件
img.onload = function(){
callback(img.width, img.height);
}
}
}
转自我的个人博客
亿登博客_一群编程爱好者的技术博客idenst.a152.cc