Skip to content

Instantly share code, notes, and snippets.

@joewright
Last active February 28, 2018 00:44
Click to spin JS
$('body').prepend('<style>@keyframes spin {from {transform:rotate(0deg);} to {transform:rotate(359deg);} } @keyframes spinrev {from {transform:rotate(0deg);} to {transform:rotate(-359deg);} }</style>');
$('body').click(function(event) {
event.preventDefault();
//use event.target with firefox
var target = event.toElement || event.target;
var spin = (Math.random() < 0.5) ? 'spin' : 'spinrev';
$(target).css('animation', spin + ' 4s infinite linear');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment