I'm trying to create a dissolve and I do this by setting the animation property like this:
var element = getElementById("myEl");
element.style.animation = "fadein 0.3s ease-out";
And then make it visible with the display property:
var element = getElementById("myEl");
element.style.display = "block";
But when I set display
to display: none
it doesn't fade out:
var element = getElementById("myEl");
element.style.display = "none";
Is there a way to set CSS so that it fades out and fades in?
Here is my fade out animation that crashes the page (since the element is invisible) when I try to use it:
@keyframes fadeout {
100% {
opacity: 1;
}
0% {
opacity: 0;
}
}
UPDATE:
Where is the pause and play animation option?
If an animation has played, how do I play it again? It's odd, since there are no play(), pause() and reverse() methods.
Here's what I'm doing to get it to play reversed after it played once. In other words, to fade out after it has faded in:
var style = overlay.style;
var animation = null;
style.animationPlayState = "paused";
if (style.animation) {
animation = style.animation;
style.animation = null;
style.animationPlayState = "paused";
overlay.addEventListener("animationend", function(event) {
log("animation ended");
overlay.removeEventListener("animationend", arguments.callee);
});
setTimeout(function() {
style.animation = animation;
style.animationPlayState = "paused";
style.animationDirection = "reverse";
style.animationPlayState = "running";
}, 30);
}