Wrapping $(document).ready inside $(window).load?

397 Views Asked by At

Based on the answer here, I need to wrap all of my code in $(window).load(function(){. However, my gallery is also using imagesLoaded (to load images when they are ready) and ajax to load more items on a button click. My current layout is like this:

function initialise(){
//code goes here, including imagesLoaded
};

$(document).ready(function(){
    initialise();
});

$(document).ajaxComplete(function () {
    initialise();

//ajax code goes here
}); 

How can I wrap all of this in $(window).load(function () {?

1

There are 1 best solutions below

1
On BEST ANSWER

Just like this!

$(window).load(function () {
    function initialise(){
    //code goes here, including imagesLoaded
    };

    $(document).ready(function(){
        initialise();
    });

    $(document).ajaxComplete(function () {
        initialise();

    //ajax code goes here
    });
});