Rotate an image with css/javascript - Javascript jQuery

Javascript examples for jQuery:Image

Description

Rotate an image with css/javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 
   </head> 
   <body> 
      <img id="rotater" onclick="rotate();" src="anyImage.png">  
      <script type="text/javascript">
    let rotateAngle = 180;/* w ww  . j  a v a 2  s .  c  om*/
    function rotate(){
        $("#rotater").css({'transform': 'rotate('+rotateAngle+'deg)'});
        rotateAngle = rotateAngle + 180;
    }

      </script> 
   </body>
</html>

Related Tutorials