I've found no way to animate gradient backgrounds, so this is a cheap way of doing so by animating the opacity of a div on top (in this case on top of the whole body, but you'd just set it to match dimensions of whatever object you want)
Created
February 28, 2014 04:58
-
-
Save kirangsa/9265544 to your computer and use it in GitHub Desktop.
A Pen by Kiran.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="blackOut"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//demo("blue","yellow"); //call the demo function | |
//demo("yellow","green"); //call the demo function | |
demo("yellow","blue"); //call the demo function | |
//A demo function - shows one colour first then switches to another | |
function demo(firstClass,secondClass) | |
{ | |
$("body").addClass(firstClass); | |
window.setTimeout(function(){ | |
changeGradient("body", firstClass,secondClass, 2000); | |
},1000); | |
} | |
//The important function, actually fades in another gradient | |
function changeGradient(object, oldClass, newClass, t) | |
{ | |
$("#blackOut").addClass(newClass); //Adds the new colour to temporary blackout div | |
$("#blackOut").animate({opacity:1},t); //Animate the blackout div opacity to 1 | |
//To match time when blackout is complete | |
window.setTimeout(function() | |
{ | |
$(object).removeClass(oldClass); //Remove old colour from object | |
$(object).addClass(newClass); //Add new colour to object | |
$("#blackOut").css({opacity:0}); //Hide blackout ready for another change | |
},t); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "compass"; | |
body, html | |
{ | |
height:100%; | |
//@extend .blue; //using this applies the blue radial straight away | |
margin:0; | |
} | |
@mixin radial($startColor, $endColor) | |
{ | |
background: $startColor; | |
background: -webkit-radial-gradient(center, ellipse cover, $startColor 0%, $endColor 100%); | |
} | |
.blue {@include radial(#499FCD, #1A69AA); } | |
.yellow {@include radial(#CD9F49, #AA691A); } | |
.green {@include radial(#9FCD49, #69AA1A); } | |
.pink {@include radial(#CD499F, #AA1A69); } | |
#blackOut | |
{ | |
height:100%; | |
width:100%; | |
margin:0; | |
opacity:0; | |
position:absolute; | |
padding:0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment