使用JQuery获取图像的真实维度 [英] Get True Dimensions of an Image with JQuery
本文介绍了使用JQuery获取图像的真实维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个图像路径列表,我如何迭代它们并找到实际的图像尺寸?我假设我必须将它们插入DOM而没有宽度或高度属性,并对它们执行.width和.height?
Given a list of image paths how can I iterate through them and find the actual image dimensions? I assume I have to insert them into the DOM without width or height properties and do a .width and .height on them?
推荐答案
var paths = ['/path/image.png', 'somewhere/page.jpg'];
$.each(paths, function(i, path) {
var img = new Image();
$(img).load(function() {
var width = img.width,
height = img.height;
alert(width + ' × ' + height);
});
img.src = path;
});
这篇关于使用JQuery获取图像的真实维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文