Reputation: 3487
I am using this code in order to fade in and out background images on my site.
var image = $('#image-holder');
image.fadeOut(1000, function () {
image.css("background", "url('images/design-" + newColor + ".jpg')");
image.fadeIn(1000);
});
but when I try:
var image = $('#image-holder');
image.fadeIn(1000, function () {
image.css("background", "url('images/design-" + newColor + ".jpg')");
image.fadeIn(1000);
});
The FadeIn effect does not trigger, Any ideas why? I want the background image to fade in not out.
Upvotes: 0
Views: 51
Reputation: 382150
You need your image to be initially hidden if you want it to fade in :
var image = $('#image-holder');
image.hide().fadeIn(1000, function () {
image.css("background", "url('images/design-" + newColor + ".jpg')");
image.fadeOut(1000); // I suppose you want fadeOut, right ?
});
Upvotes: 2
Reputation: 164
Maybe, promise with done,
var image = $('#image-holder');
image.fadeIn(1000, function () {
image.css("background", "url('images/design-" + newColor + ".jpg')").promise().done(function() {
image.fadeIn(1000);
});
});
Upvotes: -1
Reputation:
First, you must use display:none;
as opposed to opacity:0.
in order to be able to fadeIn something .
Upvotes: 0