This is the minimum reproducable example. transitionend for 'toggle' hover is firing (which I dont want) and hiding 'a' prematurely.
To reproduce click on toggle after transition ends.
I realize this is happening because toggle is inside a (I cannot change that). Is there a way to stop transitionend on toggle (without detecting which transition happend).
Its getting too complicated, finding bugy for transitionend, I would just rather use setTimeout then (which is little ridicouus for css transition).
var a = document.querySelector('.a')
a.style.display = 'block'
setTimeout(function() {
a.classList.add('visible')
}, 50)
document.querySelector('.toggle').addEventListener('click', function() {
console.log('click')
a.addEventListener('transitionend', function cb(e) {
console.log('end')
a.style.display = 'none'
})
a.classList.remove('visible')
})
.a {
position: relative;
width: 200px;
height: 200px;
background: red;
left: 200px;
display: none;
transition: left 1s;
}
.visible {
left: 0;
}
.toggle {
transition: color 0.2s;
}
.toggle:hover {
color: #fff;
}
<div class="a">
<div class="toggle">
toggle
</div>
</div>