javascript - Continuous rotate image onclick of button -


to display image used colorbox..in have add rotate-left , rotate-right rotate image.. code is:

var rotate_right = document.getelementbyid('cboxright'); $(rotate_right).on('click', function () {     var cboxphoto = document.getelementsbyclassname('cboxphoto')[0].style;     cboxphoto.setattribute('-ms-transform', 'rotate(90deg)'); });  var rotate_left = document.getelementbyid('cboxleft'); $(rotate_left).on('click', function () {     var cboxphoto = document.getelementsbyclassname('cboxphoto')[0].style;     cboxphoto.setattribute('-ms-transform', 'rotate(270deg)'); }); 

it rotate 90deg if click again on rightrotate button wont work..i want rotate again when click on button

you're ever rotating 90 or 270 degrees. when click again, doesn't move rotated angle.

keep track of current rotation instead , set attribute value plus or minus 90deg - can clean code bit well, fiddle: http://jsfiddle.net/w6ho689e/

    var degrees = 0; $("#cboxright").on('click', function () {     var $cboxphoto = $('.cboxphoto');     degrees += 90;     $cboxphoto.css('-ms-transform', 'rotate(' + degrees + 'deg)');     $cboxphoto.css('-webkit-transform', 'rotate(' + degrees + 'deg)');     $cboxphoto.css('transform', 'rotate(' + degrees + 'deg)'); });  $("#cboxleft").on('click', function () {     var $cboxphoto = $('.cboxphoto');     degrees -= 90;     $cboxphoto.css('-ms-transform', 'rotate(' + degrees + 'deg)');     $cboxphoto.css('-webkit-transform', 'rotate(' + degrees + 'deg)');     $cboxphoto.css('transform', 'rotate(' + degrees + 'deg)'); }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -