Showing a throbber during html page load and rendering

∥☆過路亽.° 提交于 2020-01-24 11:15:50

问题


I have a page that renders slowly. The trip across the net is quick. The initial load of the page is quick. You can actually see (if your machine is slow enough), the initial layout of the html components. Then some javascript stuff runs, making some of those components all ajaxy. Then finally the css gets applied.

I can't do anything about the javascript that's slowing everything to a crawl. So I need a throbber to tell the user to hold up, the browser is working. Is there any way to trap the browser is done rendering event? Is there even such an event? Is there another way to do this?


回答1:


Show the throbber before the code is run and hide it after.

Using JQuery:

$("#throbber").show();
/* Your AJAX calls */
$("#throbber").hide();



回答2:


Check to see when the DOM is ready before calling all your Ajax stuff.

using Prototype:

document.observe("dom:loaded", function() {
  //your code
});

using jQuery:

$(document).ready(function() {
      //your code
});



回答3:


Take a look on: http://plugins.jquery.com/project/throbber



来源:https://stackoverflow.com/questions/357323/showing-a-throbber-during-html-page-load-and-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!