javascript - rotate an image multiple times on click with jquery -
i trying rotate image using jquery rotate on multiple mouse clicks. using jquery-rotate plugin, following code rotates image once (transforming canvas in firefox) , no longer rotate on further clicks.
$(".drag-and-rotatable img").click(function() { $(this).rotate(45); }); i'm open using other javascript libraries.
when rotate(45), rotating image 45 degrees? (make sure it's not radians, don't use plugin) original rotation, if want keep rotating have keep adding or subtracting degrees:
$(function() { // doc ready var rotation = 0; // variable rotation $(".drag-and-rotatable img").click(function() { rotation = (rotation + 45) % 360; // mod 360 isn't needed $(this).rotate(rotation); }); });
Comments
Post a Comment