tags:

views:

33

answers:

1

Is there a way, using jQuery, to trigger an event on load of a CSS background image?

A: 

you could do it like this,

demo

​$('<img>')​.attr('src',function(){
    return $('body').css('background-image');
})​​​.load(function(){
    alert('background loaded!')
    // do triggering here....
})​;
Reigel
Would this wait until the image is loaded or until there is a return on the value of the 'background-image' property?
Squirkle
actually what happened there is it will wait for the image to load... in this case the background image of the body tag...
Reigel
That's a pretty neat trick. How does it work? I can't figure out what $('<img>') is targeting...
Squirkle