要获取图像对象的尺寸,我需要在页面上使用 JavaScript。
当我 console.log
图像对象 ($img) 时,我得到如下内容:
[<img src="/path/to/image/">]
我想获取原始图像的原始高度和宽度。我尝试使用 .naturalWidth
、.width
但这些给出了奇怪的结果。
谁能帮帮我吗?
最佳答案
据说webkit可能需要先加载图片。为此,请首先应用 onload
。
$img[0].onload = function() {
console.log(this.naturalWidth);
}
关于Javascript获取图像对象的尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28197039/