加载进度/所有内容的百分比

时间:2015-04-17 14:08:48

标签: javascript jquery load progress

我有一些文件,例如images,json ......我想在运行main()函数之前加载它们,并在加载时显示百分比的进度。 这是我的代码:

function main(){...}
function progs(imgUrlArray,jsonUrlArray,otherFilesArray){
 var total = imgUrlArray.length + jsonUrlArray.lenght + otherFilesArray.length;
 var increment =  0;
 var percent = 0;
 //method to load image
 for(var i in imgUrlArray){
  $('<img>').attr({
   src:imgUrlArray[i],
   onload : function(){
    increment++;
    percent = total/increment;
    updateProgress(percent);
   }
  })
 }
 //method to load other file here
}
function updateProgress(percent){
 $('#progressBar').width(percent*100+'%').text(percent*100+'%');
 if(percent>=1){
  $('#progressBar').text('complet').animate({opacity:0,height:0},1000,function(){
   $(this).hide();
   main();//now run the main() function
  });
 }
}

我需要这样的东西加载json&amp; 其他文件作为图片方法,但在main()运行时有效且无法正常工作,而不会显示不完整的图片或文件。

0 个答案:

没有答案