Created
February 1, 2013 17:06
-
-
Save Jazzatola/4692623 to your computer and use it in GitHub Desktop.
Random colours animated with jquery.
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
<html> | |
<head> | |
<title>Random Colors</title> | |
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script> | |
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> | |
<style type="text/css"> | |
body { | |
margin: 0; | |
} | |
#canvas { | |
display: block; | |
width: 100%; | |
height: 100%; | |
background-color: #eeeeee; | |
text-align: center; | |
} | |
#canvas span { | |
color: #ffffff; | |
background-color: transparent; | |
font-family: verdana; | |
font-size: 5em; | |
line-height: 5em; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="canvas"><span>#eeeeee</span></div> | |
<script type="text/javascript"> | |
var timer; | |
function padColor(hexString) { | |
return '#000000'.substr(0, 7 - hexString.length) + hexString; | |
}; | |
function randomColor() { | |
return padColor((~~(Math.random() * (1<<24) )).toString(16)); | |
}; | |
function changeColor() { | |
var color = randomColor(); | |
$("#canvas").animate({"background-color": color}, "slow", function() { | |
$(this).find("span").text(color); | |
console.log(color); | |
}); | |
} | |
$(function () { | |
timer = setInterval(changeColor, 2000); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment