我正在尝试为css3中的动画编写mixin。 css3中的动画需要@keyframe。但SASS(和其他声明)中的mixin声明也以@开头。就像@mixin,@ for等...所以我试图为动画编写mixin(我试图在mixin中进行所有自动化)是为了传递给CSS时将@keyfram转义为SASS解释@keyframe的@。有可能这样做吗?
示例:
@mixin animation(
//variables :
$mykeyframe:mykeyframe,
$prop1:background,
$value1-i:white,
$value1-e:red,
$prop2:color,
$value2-i:black,
$value2-e:white,
$prop3:font-weight,
$value3-i:400,
$value3-e:bold,
$time:5s,
$iteration-count:1,
$timing-function:linear,
$delay:0s,
$direction:normal,
$play-state:running
)
{//HERE'S THE PROBLEM :
@keyframes $mykeyframe{
0%{$prop1:$value1-i; $prop2:$value2-i; $prop3:$value3-i}
100%{$prop1:$value1-e; $prop2:$value2-e; $prop3:$value3-e}
}
-webkit-animation: $mykeyframe $time $iteration-count; /* Chrome, Safari 5+ */
-moz-animation: $mykeyframe $time $iteration-count; /* Firefox 5-15 */
-o-animation: $mykeyframe $time $iteration-count; /* Opera 12.00 */
animation: $mykeyframe $time $iteration-count; /* Chrome, Firefox 16+, IE 10+, Opera 12.10+ */
/* Chrome, Firefox 16+, IE 10+, Opera 12.10+ */
animation-timing-function: $timing-function;
animation-delay: $delay;
animation-direction: $direction;
animation-play-state: $play-state;
/* Safari and Chrome: */
-webkit-animation-timing-function: $timing-function;
-webkit-animation-delay: $delay;
-webkit-animation-direction: $direction;
-webkit-animation-play-state: $play-state;
}
答案 0 :(得分:3)
即使在SASS中的mixin(@mixin
)和条件(@for
,@if
等)指令以符号@
开头,您仍然可以将它用于其他不属于SASS库的关键字,如if
,mixin
等。
所以,你仍然可以这样做:
@mixin animation($mykeyframe:mykeyframe) {
@keyframes $mykeyframe {
}
}
body {
@include animation(someframe);
}
这会产生:
body {
@keyframes someframe {}
}