如何调整此解决方案(来自此处的代码: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';
用于多个图像(用于循环遍历数组)?
答案 0 :(得分: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();
答案 1 :(得分:0)
这可能会对你有所帮助
for (var i=0;i<number_of_photos;i++){
widthheight[i]=width + 'x' + height
}
通过alert(widthheight[0]);
因为我不熟悉你的代码和我不知道你真正想要什么,不能帮助更多
你正在使用jquery吗?