I am trying to upload an image and then apply fade using css background-image .
I can accomplish this when it is a regular <img src=''/> as follows:
#mainImg {display:none} var c = $('#mainImg'); $(new Image()).load(function(){ c.fadeIn(300); }).attr('src', c.attr('src'));
But how can I detect it when it is css background ?
Here's the css using jQuery, but I can't get it, like the code above, and determine when the download is complete.
$('<img/>').attr('src', 'image.png').load(function() { $('#mainImg').css('background-image', 'url(image.png)'); });
change , it helped! How to check if background image is loaded? thanks @colin
source share