jQuery:如何获取外部图像的尺寸? [英] jQuery: how to get the dimensions of a external image?
本文介绍了jQuery:如何获取外部图像的尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
寻找获取外部图像的尺寸(宽度和高度)的方法。我使用 prop()
和 attr()
,但它们不返回任何值。只是一个错误。
Looking for a way to get the dimensions (width and height) of an external image.
I have used prop()
and attr()
, but they don't return any values. Just an error.
示例:
<a href="pathtotheimage">some link</a>
推荐答案
var imgSrc = "http://server.com/your/image/path/here.jpg"
var _width, _height;
$("<img/>").attr("src", imgSrc).load(function() {
_width = this.width;
_height = this.height;
});
这篇关于jQuery:如何获取外部图像的尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文