I wrote a little code to have cards fade out and then be set to display: none;
once clicked so it's not shown in the DOM after it has faded out. Although animation-fill-mode: forwards;
works, but only the change on the display
element seems to have no effect; if you hover over the area the cursor is still there, and the element is still shown in dev tools. Is there a way to make sure that the display: none;
property is set properly?
HTML <div></div>
CSS
body {
background: black;
margin-top: 4rem;
}
div {
display: block;
background: red;
width: 200px;
height: 200px;
margin: 0 auto;
}
.hidden {
animation: hiddenTransition 300ms ease-in;
animation-fill-mode: forwards; // DOESN'T WORK :C
will-change: opacity, transform, display;
cursor: pointer;
}
@keyframes hiddenTransition {
0% {
opacity: 1;
transform: none;
display: block;
}
99% {
opacity: 0;
transform: translateY(20%);
display: block;
}
100% {
opacity: 0;
transform: translateY(20%);
display: none;
}
}
JS
var square = document.querySelector("div");
square.addEventListener("click", function(){
this.classList.toggle("hidden");
});