簡體   English   中英

如何獲取動態加載的圖像的寬度和高度?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM