Created
March 1, 2017 10:28
-
-
Save hemnathmouli/24f65933ce8faa7bc4cd04ebfe0ccf0b to your computer and use it in GitHub Desktop.
How to create a random color variable with Javascript and HTML?
This file contains 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
<html> | |
<head> | |
<title>Random Background</title> | |
<script> | |
setInterval(function(){ | |
var x = Math.round( Math.random() * 255 ); | |
var y = Math.round( Math.random() * 255 ); | |
var z = Math.round( Math.random() * 255 ); | |
var bg = "background:rgb("+x+", "+y+", "+z+");"; | |
var element = document.getElementById("random-background"); | |
element.style = bg; | |
}, 1000); | |
</script> | |
<style> | |
#random-background { | |
width: 100vw; | |
height: 100vh; | |
background: white; | |
margin: 0px; | |
transition: 1s; | |
} | |
</style> | |
</head> | |
<body id = "random-background"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment