Skip to content

Instantly share code, notes, and snippets.

@ippaiva
Created October 19, 2018 20:45
Show Gist options
  • Save ippaiva/342502b8d1dc2b5405a7883f58c9e5ef to your computer and use it in GitHub Desktop.
Save ippaiva/342502b8d1dc2b5405a7883f58c9e5ef to your computer and use it in GitHub Desktop.
GYGgaJ
<div id="color-overlay"><h1 id="text-bg">RAVE</h1></div>
// Generates a random color in hexadecimal (ie. #62b9cc)
function generateRandomColor() {
return '#'+Math.floor(Math.random()*16777215).toString(16);
}
// Changes the color of the background using STYLE
function changeBackgroundColor() {
var colorBg = document.getElementById("color-overlay")
colorBg.style.backgroundColor = generateRandomColor();
}
function changeBackgroundText() {
var textBg = document.getElementById("text-bg")
if (textBg.innerHTML == "RAVE") {
textBg.innerHTML = "OR"
} else if (textBg.innerHTML == "OR") {
textBg.innerHTML = "DIE"
} else if (textBg.innerHTML == "DIE") {
textBg.innerHTML = "RAVE"
};
}
function changeBackground() {
changeBackgroundColor();
changeBackgroundText();
}
// Run this function every 300ms
setInterval(changeBackground, 300);
body {
padding: 0px;
margin: 0px;
background-image: url("https://static.pexels.com/photos/2143/lights-party-dancing-music.jpg");
width: 100%;
height: 100vh;
background-size: cover;
}
#color-overlay {
width: 100%;
height: 100vh;
opacity: 0.8;
text-align: center;
color: #fff;
}
#text-bg {
line-height: 100vh;
font-size: 80px;
margin: 0px;
font-family: Verdana;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment