如何适应此解决方案(来自此处的代码: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';
用于多个图像(用于遍历数组)?
最佳答案
解:
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();
关于javascript - Javascript:获取多个图像数组的图像大小(宽度和高度),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19269834/