JQuery wait for page to finish loading before starting the slideshow?

前端 未结 6 603
囚心锁ツ
囚心锁ツ 2020-12-16 16:31

I have a site with a rotating header image (you\'ve all seen them). I want to do the following:

  1. Load the entire page plus the first header image
  2. Start
6条回答
  •  无人及你
    2020-12-16 16:46

    You probably already know about $(document).ready(...). What you need is a preloading mechanism; something that fetches data (text or images or whatever) before showing it off. This can make a site feel much more professional.

    Take a look at jQuery.Preload (there are others). jQuery.Preload has several ways of triggering preloading, and also provides callback functionality (when the image is preloaded, then show it). I have used it heavily, and it works great.

    Here's how easy it is to get started with jQuery.Preload:

    $(function() {
      // First get the preload fetches under way
      $.preload(["images/button-background.png", "images/button-highlight.png"]);
      // Then do anything else that you would normally do here
      doSomeStuff();
    });
    

提交回复
热议问题