Had done something like this with js.
Here is my code
document.getElementById('open_button').addEventListener('click',
function()
{
document.querySelector('.square').style.visibility = "visible";
document.querySelector('.square').style.opacity = "1";
});
document.getElementById('close_button').addEventListener('click',
function()
{
document.querySelector('.square').style.visibility = "hidden";
document.querySelector('.square').style.opacity = "0";
});
There are button for opening square with class 'open_button' and button for closing square with class 'close_button'. And the element (square, mostly modal) you want to open or close with class 'square'.
Using visibility will solve your problem with animation (for example I used opacity for smooth transition).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…