【发布时间】:2012-12-28 05:38:21
【问题描述】:
我的脚本有问题。
我正在尝试将所有图像加载到一个数组中,然后检查它们是否都已加载,然后再继续。但它不起作用我同样没有收到任何错误,所以我不确定出了什么问题。
这就是我所拥有的:
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback, element){
window.setTimeout(callback, 200 / 100);
};
})();
function img_loader(){
for(var i in Images){
Images[i]['img_src'].onload = function() {
countImages ++;
}
}
}
function img_load_checker(){
if(countImages == Images.length){
return true;
} else {
requestAnimFrame( img_load_checker ); // keep checking
}
}
window.countImages = 0;
img_loader();
if(img_load_checker()){
//this never gets executed - reason is unknown
//continue with rest of the script
}
这是console.log(Images);的结构
[1: Object, 2: Object]
1: Object
img_src: <img>
2: Object
img_src: <img>
谁能看出错误?
【问题讨论】:
-
当你说“它不工作”时,具体是什么意思?
-
你试过调试你的代码吗?控制台说了什么? JSLint 是怎么说的?
-
//continue with rest of the script这部分脚本永远不会执行。
标签: javascript