Can anyone help me to achieve that?
What I want: The loader should show up animatedly and when I click on the document the loader should hide animatedly with the same animation reversely.
Currently what's happening: For the first time the loader shows up animatedly but when I click on the document the loader hides immediately without animation. The reason is z-index.
My current code is:
HTML:
<div id="loader">
    <h1>Testing Loader</h1>
</div>
CSS:
#loader{
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0px;
    top: 0%;
    animation-duration: 1s;
    animation-fill-mode: forwards;
    background-color: brown;
    z-index: -1;
    opacity: 0;
    animation-name: hideMe;
}
#loader.hideMe{
    animation-direction: reverse;
}
@keyframes hideMe{
    0%{
        z-index: -1;
        opacity: 0;
    }
    1%{
        z-index: 15;
    }
    100%{
        z-index: 15;
        opacity: 1;
    }
}
JavaScript:
<script type="text/javascript">
    document.addEventListener('click', ()=>{
        document.querySelector('#loader').classList.toggle('hideMe');
    });
</script>
Any help will be appreciated. Thanks.
 
    