Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active November 30, 2015 13:15
Show Gist options
  • Save yratof/603247f93f67d30de357 to your computer and use it in GitHub Desktop.
Save yratof/603247f93f67d30de357 to your computer and use it in GitHub Desktop.
SCSS: Delayed sliding in list elements.
/*
* Animation and Timing Variables
*/
$element: '.menu-item'; // Pick element you want to animate
$length: 1s; // Length of animation
$stage: 0.05s; // Delay increments
$movement: 1rem; // How noticable the movment will be
$transition: cubic-bezier(0.175,0.885,0.32,1.275); // The animation easing
/*
* Give lists a nudge before they animate,
* then animate them back to original position
*/
#{$element} {
transform: translateX(#{$movement});
// When menu is open, animate!
.menu-active & {
animation: delay $length $transition forwards;
}
}
// Animation frames
@keyframes delay{
from {
transform: translateX(#{$movement});
}
to {
transform: translateX(0);
}
}
/*
* For every element in succession, delay incrementally
*/
@for $i from 1 through 10 {
$delay: $stage * $i;
#{$element}:nth-of-type(#{$i}){
animation-delay: $delay;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment