![](/img/trans.png)
[英]How to get the width and height of a dynamic loaded image in javascript?
[英]How to get the width and height of a dynamically loaded image?
如何获得动态加载的图像的宽度和高度?
<img id="thumb_320" src="dscn6691_thumb_320.jpg">
尝试使用Image
对象。 老实说,我不确定兼容性。
因此某些代码可能类似于:
var img = new Image();
img.onload = function(){
alert('Width: ' + img.width +', Height: ' + img.height);
}
img.src = 'http://www.google.com/images/logos/ps_logo2.png';
示例: http : //jsfiddle.net/EQdxw/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.