Last active
August 8, 2016 21:22
-
-
Save TeWu/a1e12472223e45d5a2d3113b4996879e to your computer and use it in GitHub Desktop.
CSS Animated Spinner (in Rails)
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
<div class='spinner-container'> | |
<div class='spinner'> | |
<% 8.times do %> | |
<div> | |
<div></div> | |
</div> | |
<% end %> | |
</div> | |
</div> |
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
<%= render 'spinner' %> |
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
@import 'utils'; | |
$spinner-size: 24px; | |
$spinner-scale: strip-unit($spinner-size - 4px) / 168; | |
$spinner-color: #777; | |
.spinner-container { | |
margin-right: $spinner-size; | |
margin-bottom: $spinner-size; | |
overflow: visible; | |
} | |
.spinner { | |
position: relative; | |
background: none; | |
transform: scale($spinner-scale); | |
& > div { | |
width: 24px; | |
height: 24px; | |
position: absolute; | |
margin-left: 4px; | |
margin-top: 4px; | |
& > div { | |
width: 100%; | |
height: 100%; | |
border-radius: 15px; | |
background: $spinner-color; | |
} | |
} | |
@for $i from 1 through 8 { | |
& > div:nth-of-type(#{$i}) { | |
transform: translate(84px, 84px) rotate(#{45 * $i}deg) translate(70px, 0); | |
& > div { | |
animation: spinner 1s linear infinite; | |
animation-delay: #{0.12 * ($i - 1)}s; | |
} | |
} | |
} | |
} | |
@keyframes spinner { | |
0% { opacity: 1; transform: scale(1.5); } | |
100% { opacity: 0.1; transform: scale(1); } | |
} |
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
// Remove the unit of a length | |
// @param {Number} $number - Number to remove unit from | |
// @return {Number} - Unitless number | |
@function strip-unit($number) { | |
@if type-of($number) == 'number' and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment