这是一个创建脉动效果的 SASS(+ Compass)功能。可以通过 $count 指定脉动数。
=keyframes($name)
@-webkit-keyframes #{$name}
@content
@-moz-keyframes #{$name}
@content
@-ms-keyframes #{$name}
@content
@keyframes #{$name}
@content
=animation-name($name)
-webkit-animation-name: $name
-moz-animation-name: $name
-o-animation-name: $name
animation-name: $name
=animation-duration($duration)
-webkit-animation-duration: $duration
-moz-animation-duration: $duration
-o-animation-duration: $duration
animation-duration: $duration
=animation-timing-function($timing-function)
-webkit-animation-timing-function: $timing-function
-moz-animation-timing-function: $timing-function
-o-animation-timing-function: $timing-function
animation-timing-function: $timing-function
=animation-iteration-count($iteration-count)
-webkit-animation-iteration-count: $iteration-count
-moz-animation-iteration-count: $iteration-count
-o-animation-iteration-count: $iteration-count
animation-iteration-count: $iteration-count
=animation-direction($direction)
-webkit-animation-direction: $direction
-moz-animation-direction: $direction
-o-animation-direction: $direction
animation-direction: $direction
// define keyframes
+keyframes(change_background_color)
to
background-color: $some_color
// define the mixin
=pulsate($time:0.2s, $count:8)
+animation-name(change_background_color)
+animation-duration($time)
+animation-iteration-count($count)
+animation-direction(alternate)
+animation-timing-function(ease-in-out)
// use the mixin in a class
.pulsate-8times
+pulsate(1s, 16)
不需要 JS(切换类除外)。将 $count 设置为 'infinite' 以获得无尽的脉动。
JSFiddle 与已编译的 CSS:http: //jsfiddle.net/3L2yA/
更新:在 SCSS 中相同(感谢http://sasstoscss.com/ ;-):
@mixin keyframes($name) {
@-webkit-keyframes #{$name} {
@content;
}
@-moz-keyframes #{$name} {
@content;
}
@-ms-keyframes #{$name} {
@content;
}
@keyframes #{$name} {
@content;
}
}
@mixin animation-name($name) {
-webkit-animation-name: $name;
-moz-animation-name: $name;
-o-animation-name: $name;
animation-name: $name;
}
@mixin animation-duration($duration) {
-webkit-animation-duration: $duration;
-moz-animation-duration: $duration;
-o-animation-duration: $duration;
animation-duration: $duration;
}
@mixin animation-timing-function($timing-function) {
-webkit-animation-timing-function: $timing-function;
-moz-animation-timing-function: $timing-function;
-o-animation-timing-function: $timing-function;
animation-timing-function: $timing-function;
}
@mixin animation-iteration-count($iteration-count) {
-webkit-animation-iteration-count: $iteration-count;
-moz-animation-iteration-count: $iteration-count;
-o-animation-iteration-count: $iteration-count;
animation-iteration-count: $iteration-count;
}
@mixin animation-direction($direction) {
-webkit-animation-direction: $direction;
-moz-animation-direction: $direction;
-o-animation-direction: $direction;
animation-direction: $direction;
}
@include keyframes(change_background_color) {
to {
background-color: $some_color;
}
}
@mixin pulsate($time: 0.2s, $count: 8) {
@include animation-name(change_background_color);
@include animation-duration($time);
@include animation-iteration-count($count);
@include animation-direction(alternate);
@include animation-timing-function(ease-in-out);
}
.pulsate-8times {
@include pulsate(1s, 16);
}