Chcę obrócić element onclick, dodając do niego klasę CSS. Problem polega na tym, że po usunięciu tej samej klasy CSS element jest obracany po raz drugi.Jak uniknąć transformacji css (obrócić) podczas usuwania klasy?
Fiddle: 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);
}
Jak mogę tego uniknąć?
Umieścić 'przejściowy: transform 1s' prefiksy (i producenta) na .rotate klasa – mhodges