Let's say you're loading a bunch of super heavy images with a js preloader (Preload.JS) and in the callback you have your $(document).ready function.

Example code:

var queue = new createjs.LoadQueue();

queue.loadManifest([
    "img/1.jpg",
    "img/2.jpg",
    "img/3.png"
]);

queue.on("complete", preloadComplete, this);

function preloadComplete() {

    $(document).ready(function() {
        //jquery stuff
    });
}

Is it possible that the preloading could take so long that the ready function gets missed?

有帮助吗?

解决方案

The ready function can't be "missed". Even if the document is already ready, the function within it will run.

http://api.jquery.com/ready

If .ready() is called after the DOM has been initialized, the new handler passed in will be executed immediately.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top