1

如何调整此解决方案(此处的代码:https ://stackoverflow.com/a/626505/975443 )

var img = new Image();
img.onload = function() {
  alert(this.width + 'x' + this.height);
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';

对于多个图像(通过数组循环)?

4

2 回答 2

2

解决方案:

var asyncI = 0;
var asyncCount = 10;

function readImageDimensions() {

    console.log('asyncI: ' + asyncI);

    var img = new Image();
    img.src = 'data/images/' + asyncI + ".png";

    img.onload = function() {

        console.log('this.width: ' + this.width + ', this.height: ' + this.height);

        asyncI++;

        if (asyncI < asyncCount) {

            //go to next loop iteration
            console.log('continue ' + asyncI);
            readImageDimensions();

        } else {

            //exit loop
            console.log('END');
            functionToContinueWith();

        }
    }
}

//call the function
readImageDimensions();
于 2013-10-09T11:00:48.060 回答
0

这可能会帮助你

      for (var i=0;i<number_of_photos;i++){ 
widthheight[i]=width + 'x' + height
}

提醒第一个通过alert(widthheight[0]);

因为我不熟悉你的代码&我不知道你真正想要什么不能帮助更多

你在使用 jquery 吗?

于 2013-10-09T10:57:14.040 回答