My objective is to animate an item to swing only when hovered over, utilizing CSS and jQuery, and of course, it should stop swinging when the mouse moves away.
After browsing the web, I came across a code snippet that swings an element when the document is loaded (view complete jsFiddle).
$(document).ready(function() {
function swing(){
$('.swing').toggleClass('right');
setTimeout(swing, 1000);
}
swing();
});
I attempted to use the .hover() method, but unfortunately, it did not work as expected. What steps can help me resolve this minor issue?