fadejquery fadejquery - 16 days ago 8
jQuery Question

jquery: fade css background image change

I want to fade the images when I do this code:

$("#large-img").css('background-image', 'url('+$img+')');


I've tried putting fade in so many places.

Thanks

Answer

This is probably what you wanted:

$('#elem').fadeTo('slow', 0.3, function()
{
    $(this).css('background-image', 'url(' + $img + ')');
}).fadeTo('slow', 1);

With a 1 second delay:

$('#elem').fadeTo('slow', 0.3, function()
{
    $(this).css('background-image', 'url(' + $img + ')');
}).delay(1000).fadeTo('slow', 1);