我现在有个图片是通过js读取出来得。类似下面得这样<img style="position: absolute; left: 2384px; top: 0px; display: none;" src="../3.jpg">
<img style="position: absolute; display: block; z-index: 6; left: 0px; top: 0px; opacity: 1;" src="../4.jpg">
<img style="position: absolute; top: 0px; left: -2384px; display: none; z-index: 5;" src="../5.jpg">
<img style="position: absolute; top: 0px; left: 0px; display: none; z-index: 3; opacity: 1;" src="../1.jpg">
<img style="position: absolute; top: 0px; left: 0px; display: none; z-index: 2;" src="../2.jpg">这些图片都没有长度和高度~~~所以图片得尺寸太大得话,就显示不全了,我需要判断下,大得图片就缩小,小的尺寸不变我怎么样能得到图片实际得大小?
高手帮忙
<img style="position: absolute; display: block; z-index: 6; left: 0px; top: 0px; opacity: 1;" src="../4.jpg">
<img style="position: absolute; top: 0px; left: -2384px; display: none; z-index: 5;" src="../5.jpg">
<img style="position: absolute; top: 0px; left: 0px; display: none; z-index: 3; opacity: 1;" src="../1.jpg">
<img style="position: absolute; top: 0px; left: 0px; display: none; z-index: 2;" src="../2.jpg">这些图片都没有长度和高度~~~所以图片得尺寸太大得话,就显示不全了,我需要判断下,大得图片就缩小,小的尺寸不变我怎么样能得到图片实际得大小?
高手帮忙
document.images[0].onload=function(){
alert(this.width);
}
但是,必须首先让图片可见,如果display为none,加上document.images[0].style.display ="block"。
//保证图片小于50*50px
this.width=(this.width>50?50:this.width);
this.height=(this.height>50?50:this.height);
}
<img onload="resize(this,100)" style="position: absolute; left: 2384px; top: 0px; display: none;" src="../3.jpg">
//function resize(img, size, callback)
//{
// var n = new Image();
// n.src = img.src;// if (Browser.msie) ok();
// else n.onload = function ()
// {
// if (n.complete == true) ok();
// }// function ok()
// {
// var w = n.width, h = n.height;
// if (w >= size) { h = size * h / w; w = size; }
// if (h >= size) { w = size * w / h; h = size; }
// img.width = w; img.height = h;
// if (callback) callback.call(img, size, [n.width, n.height]);
// n = null;
// }
//};
图片有onload事件的