0

I'm trying to make the gradient fade in as the background color.

$('body').animate({
  background: '-webkit-gradient(linear,left top,left bottom,from(#b0c4ff),to(#6289ff)) fixed)'
}, 2000, function(){});

http://jsfiddle.net/myLf9o0j/3/

jQuery animate backgroundColor

Animation in css with gradient colors

Community
  • 1
  • 1
Squirrl
  • 4,909
  • 9
  • 47
  • 85

1 Answers1

4

Make a full page div and add it on the background behind all other elements. Then you can make it animate.

Check the code below:

function goodMorning(){
 $('#background').animate({
            opacity: 1
 }, 2000);
}

goodMorning();
body{
    background-color: red;
}
#background{
    opacity: 0;
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    z-index: -1;
    background: -webkit-gradient(linear,left top,left bottom,from(#b0c4ff),to(#6289ff)) fixed;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="background"></div>
<p>Hello :)</p>
GramThanos
  • 3,572
  • 1
  • 22
  • 34