用rotateTimes记录旋转次数,从而旋转不同的角度,很简单,直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>每点击一下,旋转90°</title>
<style>
#box{
width: 150px;
height: 120px;
background: red;
margin: 100px;
border-bottom: 2px solid black;
}
</style>
</head>
<body>
<div id = "box"></div>
<script>
var box = document.getElementById("box");
var rotateTimes = 1;
box.onclick = function(){
box.style.webkitTransform = 'rotate('+90*rotateTimes+'deg)';
box.style.mozTransform = 'rotate('+90*rotateTimes+'deg)';
box.style.msTransform = 'rotate('+90*rotateTimes+'deg)';
box.style.oTransform = 'rotate('+90*rotateTimes+'deg)';
box.style.transform = 'rotate('+90*rotateTimes+'deg)';
console.log("finished");
rotateTimes++;
}
</script>
</body>
</html>
6423

被折叠的 条评论
为什么被折叠?



