Reversing a css animation -
i have overlay fades in following code,
.overlay { background: rgba(32, 79, 156, 0.97); width: 100%; height: 100vh; position: fixed; z-index: 1000; display: none; } .overlay.active { display: block; -webkit-animation-duration: 0.5s; -webkit-animation-name: fadein; animation-duration: 0.5s; animation-name: fadein; } @keyframes fadein { 0% { display:none; opacity: 0; } 1% { display: block ; opacity: 0; } 100% { display: block ; opacity: 1; } }
all js toggle class
$('.hamburger').on('click', function(){ $('.overlay, .hamburger').toggleclass('active'); });
how can reverse animation? @ moment jumps previous state.
animations won't work on display
property display:none
hides element wouldn't see fade if animation running. can animate opacity
property using css transitions this:
$('.hamburger').on('click', function(){ $('.overlay, .hamburger').toggleclass('active'); });
.overlay { background: rgba(32, 79, 156, 0.97); width: 100%; height: 100vh; position: fixed; z-index: 1000; opacity:0; pointer-events:none; -webkit-transition: scale, opacity 0.5s ease; -moz-transition: scale, opacity 0.5s ease; -o-transition: scale, opacity 0.5s ease; transition: scale, opacity 0.5s ease; } .overlay.active { opacity:1; pointer-events:auto; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="hamburger">hamburger</div> <div class="overlay">overlay</div>
Comments
Post a Comment