the following code is this.
const showBoxBtn = document.querySelector('.showBox');
const closeBoxBtn = document.querySelector('.closeBox');
const box = document.querySelector('.box');
const showBox = function () {
box.classList.remove('hidden');
}
const closeBox = function () {
box.classList.add('hidden')
}
showBoxBtn.addEventListener('click', showBox );
closeBoxBtn.addEventListener('click', closeBox);
.box {
width: 100px;
height: 100px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #000;
display:flex;
position: absolute;
animation: slide-in-top 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}
@keyframes slide-in-top {
0% {
transform: translateY(-1000px);
opacity: 0;
}
100% {
transform: translateY(0), translate(-50%, -50%);
opacity: 1;
}
}
.hidden {
display:none;
}
<button class="showBox">Show</button>
<button class="closeBox">Close</button>
<div class="box hidden"></div>
The problem is the animation don't work on classList.remove. I want to make same animation , or reverse or another.
You can find the JSFiddle here.
I hope you can help me!
Thanks