Rotate image with javascript

后端 未结 9 792
温柔的废话
温柔的废话 2020-11-27 04:17

I need to rotate an image with javascript in 90-degree intervals. I have tried a few libraries like jQuery rotate and Raphaël, but they have the same problem - The image is

9条回答
  •  鱼传尺愫
    2020-11-27 04:40

    No need for jQuery and lot's of CSS anymore (Note that some browsers need extra CSS)

    Kind of what @Abinthaha posted, but pure JS, without the need of jQuery.

    let rotateAngle = 90;
    
    function rotate(image) {
      image.setAttribute("style", "transform: rotate(" + rotateAngle + "deg)");
      rotateAngle = rotateAngle + 90;
    }
    #rotater {
      transition: all 0.3s ease;
      border: 0.0625em solid black;
      border-radius: 3.75em;
    }

提交回复
热议问题