预加载百分比 – javascript / jquery

我做了谷歌搜索,我找不到用百分比加载的方法。 有谁知道我怎么能找到一个例子?

我需要一个网站的预加载从0到100没有条,在显示内容之前,但我找不到任何例子。

如果您的意思是只想在完全加载时显示内容,您可以尝试以下两个选项:

1)将所有内容包装在

标记内,并在加载完成事件中显示如下:

 $(function(){ $("#wrapper").show(); }); 

2)如果仍然无法解决您的目的,您可以使用ajax加载空白页面并获取内容:

 $(function(){ $.ajax({ .......//AJAX params ....... success:function(msg){ $("#wrapper").html(msg);//DO NEEDFUL WITH THE RETURNED VALUE }); }); 

编辑:使用queryLoader提供的queryLoader脚本,我取得了一些成功:D

我必须对第127行到第151行的queryLoader.js文件进行一些更改。更改后的脚本如下所示。 亲自尝试一下。

 $(QueryLoader.loadBar).css({ position: "relative", top: "50%", font-size:40px; font-weight:bold; line-height:50px; height:50px; width:100px; }); }, animateLoader: function() { var perc = (100 / QueryLoader.doneStatus) * QueryLoader.doneNow; if (perc > 99) { $(QueryLoader.loadBar).stop().animate({ width: perc + "%" }, 5000, "linear", function() { $(this).html("100%");//MY EDIT QueryLoader.doneLoad(); }); } else { $(QueryLoader.loadBar).stop().animate({ width: perc + "%" }, 5000, "linear", function() { //MY EDIT $(this).html(""+Math.round(perc)+"%"); }); } }, 

我推荐这个插件。 来自http://demo.inwebson.com/download/jpreloader.zip的精彩下载请参见http://www.inwebson.com/demo/jpreloader/

   

这里是新版本jpreloader 2.1的链接http://demo.inwebson.com/download/jpreloader-v2.zip http://www.inwebson.com/demo/jpreloader-v2/

你不能。

正如zzzzBov所说,目前尚不清楚会有多少内容,或内容的大小。

你可以用这样的东西“伪造”它(例如我正在使用图像):

 var percentCounter = 0; $.each(arrayOfImageUrls, function(index, value) { $('').attr('src', value) //load image .load(function() { percentCounter = (index / arrayOfImageUrls.length) * 100; //set the percentCounter after this image has loaded $('#yourProgressContainer').text(percentCounter + '%'); }); }); 

正如我所提到的,这不是网站加载的真实百分比,而是对已加载图像的粗略估计,假设每个图像的大小大致相同。