获取url jquery指定的图像的宽度

Kib*_*bou 4 jquery

我想读出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)

我需要它:http: //foto.hendrik-schicke.de/index.php/people

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/