Skip to content

Instantly share code, notes, and snippets.

@andrewgremlich
Last active January 18, 2019 02:15
Show Gist options
  • Save andrewgremlich/c6a8d5559ca03e9d2e68e91779a0e8a8 to your computer and use it in GitHub Desktop.
Save andrewgremlich/c6a8d5559ca03e9d2e68e91779a0e8a8 to your computer and use it in GitHub Desktop.
const backgroundGradient = (() => {
let grad = document.querySelector('body'),
degree = 0,
red = 200,
green = 0,
blue = 100,
redup = true,
greenup = false,
blueup = false;
const genRGBcolorSet1 = () => `${red}, ${green}, ${blue}`;
const genRGBcolorSet2 = () => `${green}, ${red}, ${blue}`;
const animateGradient = () => {
grad.style.background = `linear-gradient(${degree}deg, rgb(${genRGBcolorSet1()}), rgb(${genRGBcolorSet2()}))`;
degree++;
if (red === 254) redup = false;
if (red === 1) redup = true;
redup ? red++ : red--;
if (green === 254) greenup = false;
if (green === 1) greenup = true;
greenup ? green++ : green--;
if (blue === 254) blueup = false;
if (blue === 1) blueup = true;
blueup ? blue++ : blue--;
if (degree === 361) degree = 0;
}
setInterval(animateGradient, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment