我想读出for循环中由url指定的图像的宽度(orgWidth),为480px的高度计算其新宽度(calcWidth)。
for (var i=1; i <= item.length; i++) {
url = document.images[i].rsc;
orgWidth = some-fancy-thing-that-reads-the-width;
orgHeight = some-fancy-thing-that-reads-the-height;
factor = orgHeight / 480 // 1400 / 480 = 2.916
calcWidth = orgWidth / factor // 1000 / 2.916 = 342.935
document.images[i].width = calcWidth;
}
我需要它的页面:
http://foto.hendrik-schicke.de/index.php/people
最佳答案
var tmpImg = new Image();
tmpImg.src="https://www.google.com/intl/en_com/images/srpr/logo3w.png"; //or document.images[i].src;
$(tmpImg).on('load',function(){
var orgWidth = tmpImg.width;
var orgHeight = tmpImg.height;
alert(orgWidth+"x"+orgHeight);
});
演示:http://jsfiddle.net/eWzWg/3/