Grow your CSS skills. Land your dream job.

jQuery : Wait till image load before applying function : How

  • # June 30, 2009 at 1:07 pm

    How do I get jquery to wait till an image has loaded before it acts. Can I?

    # June 30, 2009 at 10:26 pm

    Wrap your code in this:

    Code:
    $(window).bind(“load”, function() {

    });

    instead of

    Code:
    $(function() {

    });

    # July 2, 2009 at 1:06 pm

    @chriscoyier: this makes the code ‘wait’ until the entire page is loaded. I think this is more specific:

    Code:
    $(‘#someImageID’)
    .load(
    function(){
    //Do stuff once the image specified above is loaded
    }
    );

    Place that piece of code outside your $(function() { }); or $(document).ready(function(){ });, in this way the function above will be executed when just that specific image was loaded, not the entire page.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".