Last active
February 28, 2018 00:44
-
-
Save joewright/16ca1fa997f72922e4c4f3b6cac3e70b to your computer and use it in GitHub Desktop.
Click to spin JS
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
$('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