Right now, I’m using switchClass to change the body backgound. The change is instant and not easy on the eyes.
$('.Click').click(function () {
var thisClass = $(this).attr('class');
var st = thisClass.split(' ');
var firstClass = st[0];
if (firstClass == "item1") {
$('.mask').animate({
marginLeft: "-100%"
}, 600, function () {
$("body").switchClass($("body").attr("className"), "bg1");
});
} else if (firstClass == "item2") {
$('.jobsMask').animate({
marginLeft: "-200%"
}, 600, function () {
$("body").switchClass($("body").attr("className"), "bg2");
});
}
});
How do I animate this / make this less abrupt?
For
background-colorfading:You can use a transition on the
bodyelement to animate changes to thebackgroundproperty like this:test it: http://jsbin.com/odabit/2/edit
For fading background images:
Transitions don’t seem to work on
background-image(EDIT: they work in Chrome, but not in Fx16, Opera12.1, or IE9), so my workaround is to put your bg images on separate divs, and then fade those in and out, like this: http://jsbin.com/odabit/7/editThe switching code looks like this:
And the CSS to support it: