【发布时间】:2021-10-29 02:16:00
【问题描述】:
我想编写一个 javascript 来通过单击一个按钮来连续旋转图像。我可以通过点击进行部分旋转。我认为我应该递归调用该函数以获得连续旋转,但我不知道该怎么做。 以下是我的代码。
<html>
<head>
<title>Image Rotation</title>
</head>
<body>
<button id="rotate">Rotate</button>
<img src="images/circle.png" id="sample" ;" alt="" />
</body>
<script>
var rotation = 0;
document.querySelector("#rotate").addEventListener('click', function() {
rotation += 90;
document.querySelector("#sample").style.transform = 'rotate(' + rotation + 'deg)';
});
</script>
</html>
【问题讨论】:
-
到目前为止,您有什么尝试自己解决这个问题(例如
setInterval())? -> How much research effort is expected of Stack Overflow users? -
一个CSS动画会更好
标签: javascript rotation