Skip to content

Instantly share code, notes, and snippets.

@shotasenga
Created March 7, 2015 18:07
Show Gist options
  • Save shotasenga/4e058ac3f0df05a21b4e to your computer and use it in GitHub Desktop.
Save shotasenga/4e058ac3f0df05a21b4e to your computer and use it in GitHub Desktop.
SCSS mixin instead of `steps()` timing function. some old Android browsers not supported steps() timing function.
@mixin step-frames($steps, $fromX, $fromY, $toX, $toY){
$i: 0;
$frame: 0;
@while $frame < 100 {
@if $frame > 0{
#{$frame - 0.00001}% {
background-position: #{($toX - $fromX) / $steps * ($i - 1)}px #{($toY - $fromY) / $steps * ($i - 1)}px;
}
}
#{$frame}% {
background-position: #{($toX - $fromX) / $steps * $i}px #{($toY - $fromY) / $steps * $i}px;
}
$i: $i + 1;
$frame: $frame + 100 / $steps
}
}
.animate {
@include animation(anim 3s 1);
}
@include keyframes(anim){
@include step-frames(24, 0, 0, 0, -2785);
}
// above SCSS code is instead of ...
.animate {
@include animation(anim 3s steps(24));
}
@include keyframes(anim){
0% {
background-position: 0 0;
}
100%{
background-position: 0 -2785px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment