クリックするごとに、divは90°回転します.

6325 ワード

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>