I have a ul
and on click of one of its li
I want to hide sub ul
in it with sliding effect. I have tried animation
with height
from 100% to 0. But this is not working.
This is code snippet and in real scenario there will be dynamic data and n no of li
function hide() {
var li = document.getElementById("game");
game.classList.add("hide")
}
.hide {
height: 0;
overflow: hidden;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {
height: 100%;
}
25% {
height: 75%;
}
50% {
height: 50%;
}
100% {
height: 0%;
}
}
<ul>
<li>A</li>
<li onclick="hide()">b</li>
<li id="game" style="height:100%">
<ul>
<li>1</li>
<li>2</li>
</ul>
</li>
</ul>
How can I achieve this?