Skip to content

Instantly share code, notes, and snippets.

@brybrophy
Last active June 20, 2017 00:18
Show Gist options
  • Save brybrophy/36a09de3e1747813bed6bae63d5b5625 to your computer and use it in GitHub Desktop.
Save brybrophy/36a09de3e1747813bed6bae63d5b5625 to your computer and use it in GitHub Desktop.
A SASS mixin to slide an element in any cardinal direction, at any speed, for any distance.
// example 1: @include slide(up, 125ms, 100%);
// example 2: No distance required for "off" @include slide(off, 125ms);
// example 3:
// div {
// @include slide(up, 250ms, 100%);
//
// &.is-visible {
// @include slide(off, 125ms);
// }
// }
@function slide($direction, $distance) {
$slide: (
down: translateY($distance),
left: translateX(-$distance),
off: translate(0, 0),
right: translateX($distance),
up: translateY(-$distance)
);
@return map-get($slide, $direction);
}
@mixin slide($direction, $speed, $distance: 0) {
transform: slide($direction, $distance);
transition: all $speed ease-in-out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment