Last active
June 1, 2023 04:11
-
-
Save aurooba/7941f00576d9b649afe28f70fda0436c to your computer and use it in GitHub Desktop.
A simple mixin to to animate an element to fade it in or fade it out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Simple fade-in/out animation | |
/// @param {String} $type - "show" or "hide", defaults to "show" | |
/// @param {Number} $delay - Animation delay in seconds | |
/// @param {Number} $duration - Animation duration in seconds | |
/// @param {String} $timing-function - Animation timing function, defaults to "ease-in" | |
@mixin fade( | |
$type: "show", | |
$delay: 0s, | |
$duration: 0.5s, | |
$timing-function: ease-in, | |
) { | |
@if $type == "hide" { | |
animation: $duration fadeOutAnimation $timing-function; | |
animation-delay: $delay; | |
animation-fill-mode: forwards; | |
@keyframes fadeOutAnimation { | |
to { | |
visibility: hidden; | |
opacity: 0; | |
} | |
} | |
} @else if $type == "show" { | |
animation: $duration fadeInAnimation $timing-function; | |
animation-delay: $delay; | |
animation-iteration-count: 1; | |
@keyframes fadeInAnimation { | |
0% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment