Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery : Wait till image load before applying function : How

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #25314
    mattvot
    Member

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

    #59960
    Chris Coyier
    Keymaster

    Wrap your code in this:

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

    });

    instead of

    Code:
    $(function() {

    });

    #60075
    Hugo
    Member

    @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)
  • The forum ‘JavaScript’ is closed to new topics and replies.