Skip to content

Instantly share code, notes, and snippets.

@yspreen
Created March 22, 2018 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yspreen/8e1b4e51d2e90a298ee0041577250410 to your computer and use it in GitHub Desktop.
Save yspreen/8e1b4e51d2e90a298ee0041577250410 to your computer and use it in GitHub Desktop.
SASS ultimate transition mixin [SCSS]
@function remove-nth($list, $index) {
$result: null;
@if type-of($index) != number {
@warn "$index: #{quote($index)} is not a number for `remove-nth`.";
} @else if $index == 0 {
@warn "List index 0 must be a non-zero integer for `remove-nth`.";
} @else if abs($index) > length($list) {
@warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";
} @else {
$result: ();
$index: if($index < 0, length($list) + $index + 1, $index);
@for $i from 1 through length($list) {
@if $i != $index {
$result: append($result, nth($list, $i));
}
}
}
@return $result;
}
/*
usage: @include simple_transition(prop 0.5s cubic-bezier(0.16, 0.85, 0.45, 1));
*/
@mixin simple_transition($value) {
-webkit-transition: $value;
-moz-transition: $value;
-ms-transition: $value;
-o-transition: $value;
transition: $value;
}
/*
usage: @include transition(prop1, prop2, ..., 0.5s cubic-bezier(0.16, 0.85, 0.45, 1));
*/
@mixin transition($args...) {
$type: nth($args, length($args));
$props: remove-nth($args, length($args));
$result: ();
@for $i from 1 through length($props) {
$prop: nth($props, $i);
$result: append($result, $prop);
$result: append($result, $type);
@if $i != length($props) {
$result: append($result, unquote($string: ","));
}
}
@include simple_transition($result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment