我想让网页上的元素在每次单击按钮时逆时针旋转 360 度。我找到了一些示例代码,展示了如何执行此操作,但唯一的问题是当前它以交替方向旋转。
有没有一种简单的方法可以确保元素每次都沿同一方向旋转?
$('button').click(function() {
$('.box').toggleClass('box-rotate');
});Run Code Online (Sandbox Code Playgroud)
.box {
background: lightblue;
width: 200px;
height: 200px;
margin: 20px auto;
transition: transform 1s linear;
transform-origin: top left;
transform-style: preserve-3D;
}
.box-rotate {
transform: rotate(360deg);
}
button {
display: block;
margin: auto;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="box"></div>
<button>click me</button>Run Code Online (Sandbox Code Playgroud)