Last active
March 4, 2016 02:35
-
-
Save mishelen/36af8378b28a9eea4d1f to your computer and use it in GitHub Desktop.
зацикленная анимация для спиннера.
Создаем псевдо-элемент. Здесь достаточно навешивать класс на объект, или отслеживать :hover.
Круг плавающий внутри кольца.
Стоит не забыть добавить объкту position: relative;
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 loading($name, $big_radius:50,$little_radius:10,$big_stroke:10,$little_stroke:5,$speed:4s,$res:40) { | |
| &:before{ | |
| content:''; | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| width: ($big_radius*2) +px; | |
| height: ($big_radius*2) +px; | |
| z-index: 999; | |
| border-radius: 50%; | |
| border: solid $big_stroke+px rgba(10,120,255,.5); | |
| transform: translate( 0- $big_radius + px, 0- $big_radius +px); | |
| } | |
| &:after{ | |
| content:''; | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| width: $little_radius+px; | |
| height: $little_radius+px; | |
| z-index: 999; | |
| border-radius: 50%; | |
| border: solid $little_stroke+px rgba(255,255,255,.8); | |
| animation-name: #{$name} ; | |
| animation-duration: $speed; | |
| animation-iteration-count: infinite; | |
| } | |
| // Генерация кадров, их много но меньше чем svg или img, | |
| // частоту можно настроить через $res | |
| @keyframes #{$name} { | |
| @for $i from 0 through $res { | |
| $x: floor( ($big_radius - ($big_stroke/2)) * cos( 2 * pi() * ($i / $res)) - ($little_radius/2) ); | |
| $y: floor( ($big_radius - ($big_stroke/2)) * sin( 2 * pi() * ($i / $res)) - ($little_radius/2) ); | |
| #{($i/$res)*100}% { transform: translate($x + px,$y + px); } | |
| } | |
| } | |
| } | |
| // Применяем так | |
| .example-1{ | |
| @include loading('example-1',80,20,20,10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment