Reputation: 2702
I have a working code that changes my document background image when links in my navbar are clicked. The background image changes instantly with no animation. How could I make the new background image fadeIn(); ?
js
$('.navigation a').click(function() {
currentBg = $(this).attr('href').replace('#', '') +'.jpg';
$('.background').css({'background-image':'url(images/skins/'+currentBg+')'});
});
Upvotes: 1
Views: 331
Reputation: 1
As many others already said, it's impossible unless you use a block element as background. But if you only want an animation, you could have a .gif as background then when it's animation has finished replace it with the real Image so the .gif doesn't iterate itself
Upvotes: 0
Reputation: 2661
I agree with int0x90.
What you can do is this:
hope this helps get you started!
Upvotes: 0
Reputation: 492
I've done something like this before by floating a foreground image on a separate div on top of the background image you'd like to 'fade' in and then creating a jquery fade-out effect on the foreground image.
You can use a similar trick to set solid text on a semi-transparent "background".
http://css-tricks.com/non-transparent-elements-inside-transparent-elements/
Upvotes: 0
Reputation: 3095
There is no possiblity to fade the background image, you have to create a container and set its background image to let it fade in and fade out.
Upvotes: 0
Reputation: 69905
You cannot animate the background image changing its opacity.
May be you can have a image with required opacity at different sections and then animate the background position so that it gives a fadeIn
behavior.
Take a look at this link it will help you.
Upvotes: 0
Reputation:
I don't believe you can, the only way (that I know of) would be to have a block element (div for example) which has the background and that appears behind the rest of your content (positioned absolutely) and fade that in instead of switching backgrounds.
Upvotes: 3