Skip to content

Instantly share code, notes, and snippets.

@martinogden
Created January 8, 2010 12:30
Show Gist options
  • Save martinogden/272023 to your computer and use it in GitHub Desktop.
Save martinogden/272023 to your computer and use it in GitHub Desktop.
// Requires jQuery Rotate Plugin - http://wilq32.googlepages.com/wilq32.rollimage222
$(function()
{
var angle;
function begin_rotation(override_angle)
{
// Generate random number between 15 and 35 for rotation distance
amount = Math.floor(Math.random()*36);
while(amount < 15)
{
amount = Math.floor(Math.random()*36);
}
angle = override_angle? override_angle : 0;
rotate = setInterval(function(){do_rotation();}, 100);
}
// Initial Angle to rotate by
function do_rotation()
{
if(amount < 1)
{
// Stop rotation
clearInterval(rotate);
}
// Slow down rotation
angle+=amount;
amount = amount - 0.5;
$('#cog').rotateAnimation(angle);
}
// begin_rotation();
// Rotate when button / link is pressed
$("#fortune").click(function()
{
begin_rotation(20);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment