// minilab7.js
// Sample JavaScript solution for Mini-lab 7: Catch Me If You Can!
// INFO 343, Autumn 2012
// Morgan Doocy
// Attach event handlers when the page is ready.
$(document).ready(function() {
// Exercise 2
// Make #catchme move to a random location when the mouse moves over it.
$('#catchme').mouseover(runaway);
// Exercise 4
// When #catchme is clicked, apply the 'caught' class to it.
$('#catchme').click(caught);
});
// Exercise 2
// Set the 'left' and 'top' CSS properties of this element to random coordinates
// within the window.
function runaway() {
var top = Math.floor(Math.random() * window.innerHeight);
var left = Math.floor(Math.random() * window.innerWidth);
$(this).css({
'top': top + 'px',
'left': left + 'px'
});
}
// Exercise 4
// Add the 'caught' class to this element.
function caught() {
$(this).addClass('caught');
}