给定一个图像路径列表,我如何迭代它们并找到实际的图像尺寸?我假设我必须将它们插入DOM而没有宽度或高度属性,并对它们执行.width和.height?
答案 0 :(得分:4)
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;
});