$(window).load(function() {
//获取div的宽度,设置div正方形
var width1=document.getElementById("div1").offsetWidth;$("#div1").css("height",width1).find("img").show();
//获取图片的真实宽高
var _w=parseInt($(window).width());$(".con02 img").each(function(){
var img = $(this);
var realWidth;//真实的宽度
var realHeight;//真实的高度
$("<img/>").attr("src", $(img).attr("src")).load(function() {
realWidth = this.width;
realHeight = this.height;
if(realWidth>=_w){
$(img).css("width","100%").css("height","auto");
}
else{
$(img).css("width",realWidth+'px').css("height",realHeight+'px');
}
})
})
})
网上发现一个定时检测图片宽高的方法,效率非常高。具体代码如下:
代码如下 | 复制代码 |
// 记录当前时间戳 |
转载链接:http://www.111cn.net/wy/js-ajax/68065.htm