Skip to content

Instantly share code, notes, and snippets.

@artlung
Created May 1, 2010 17:46
Show Gist options
  • Save artlung/386519 to your computer and use it in GitHub Desktop.
Save artlung/386519 to your computer and use it in GitHub Desktop.
random-color-jquery.html
<html>
<head>
<title>My Random Color Sample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var new_num = 40; // global variable
function randomWebColor() {
var number_of_colors = 0xffffff;
var num = Math.round(Math.random() * number_of_colors);
return ('#0' + num.toString(16)).replace(/^#0([0-9a-f]{6})$/i, '#$1');
}
jQuery(document).ready(function(){
// http://api.jquery.com/bind/
// http://api.jquery.com/css/
// http://api.jquery.com/text/
$('#countme').css({
margin: '0 auto',
backgroundColor: '#ccc',
textAlign: 'center',
fontSize: '40px'
}).bind('click mousemove', function(){
var current = parseInt($(this).text(), 10);
new_num = new_num + 1
$(this).text(current+1).css({fontSize: new_num+'px', color: randomWebColor(), backgroundColor: randomWebColor() });
});
});
</script>
</head>
<body style="margin: 0">
<div id="countme">0</div>
<a href="http://api.jquery.com/">Learn more about jQuery's methods</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment