Skip to content

Instantly share code, notes, and snippets.

@aurooba
Last active June 1, 2023 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aurooba/7941f00576d9b649afe28f70fda0436c to your computer and use it in GitHub Desktop.
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.
/// 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