Created
March 7, 2015 18:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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