Skip to content

Instantly share code, notes, and snippets.

@artlili
Created January 2, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlili/1b37791d1592e13de6fd373e0528f3bd to your computer and use it in GitHub Desktop.
Save artlili/1b37791d1592e13de6fd373e0528f3bd to your computer and use it in GitHub Desktop.
Dynamic Gradient Background
$bg-color: #ff8888; //start color
$stops: 100; //smoothness
$time: 20s; //duration of animation
$hue-range: 20; //of 360deg
body{
background-color: $bg-color;
-webkit-animation: colorChange $time linear 0s infinite;
animation: colorChange $time linear 0s infinite ;
}
@-webkit-keyframes colorChange{
@for $i from 0 through $stops{
$old-color: adjust-hue($bg-color, (360/$stops)*$i);
$new-color: adjust-hue($bg-color, (360/$stops)*$i + $hue-range);
#{$i}% {
background: -webkit-linear-gradient(left, $old-color, $new-color);
background: linear-gradient(to right, $old-color, $new-color);
}
}
}
@keyframes colorChange{
@for $i from 0 through $stops{
$old-color: adjust-hue($bg-color, (360/$stops)*$i);
$new-color: adjust-hue($bg-color, (360/$stops)*$i + $hue-range);
#{$i}% {
background: linear-gradient(to right, $old-color, $new-color);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment