문제

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