I did some CSS transitions with opacity changes. Via javascript they started by adding a new class or removing them.
It's like:
.element {
opacity: 0;
z-index; -1;
display: none;
transition: opacity .2s linear;
}
.changeDisplay {
display: block;
}
.show {
z-index: 1;
opacity: 1
}
Via javascript i made a eventListener that fires the class changes after a click. At first the .changeDisplay class will added, after a setTimeout (delay, 4)
function the .show class will added too. The 4ms (should be the min allowed delay value) delay is important for the fade in animation (opacity transition) to work.
The problem is - sometimes this won't work as expected! The animation is sometimes laggy so the animation effekt isn't working at all (it looks like it just showed up via a display change).
Why is that and what can i do better to get smooth animations every single time? I observed this behavior in Chrome (also on android mobile chrome), Opera, Firefox and IE (Safari wasn't tested because of a lack of apples in my house).