I want to rotate the onclick element by adding a CSS class to it. The problem is that when the same CSS class is removed, the element rotates a second time.
script: https://jsfiddle.net/L3x2zhd1/1/
JS:
var el = document.getElementById('el'); el.onclick = function() { el.className = 'rotate' setTimeout(function(){ el.className = '' },1000) };
CSS
#el { width: 50px; height: 50px; background-color: red; -webkit-transition: -webkit-transform 1s; transition: transform 1s; } .rotate { -webkit-transform: rotate(180deg); transform: rotateX(180deg); }
How can i avoid this?
source share