When the mouse hovers over, the square will rotate in a clockwise direction for odd-numbered hover events and in an anticlockwise direction for even-numbered hover events.
var box = document.getElementById("box")
function rotate() {
//if ( ? ? ? ) {
// box.className = 'even';
//} else {
// box.className = 'odd';
//}
}
#box {
width: 100px;
height: 100px;
background: red;
transition: transform 1s;
}
.even {
transform: rotate( -180deg);
/* transition: transform 150ms ease; */
}
.odd {
transform: rotate( 180deg);
/* transition: transform 150ms ease; */
}
<div id="box" onmouseover="rotate()"></div>