我想读出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;
}
Run Code Online (Sandbox Code Playgroud)
Muh*_*man 10
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);
});
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/eWzWg/3/
| 归档时间: |
|
| 查看次数: |
11824 次 |
| 最近记录: |