我正在尝试为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;
}
最佳答案
尽管 SASS 中的 mixin (@mixin
) 和条件指令 (@for
, @if
等) 指令以符号开头@
,您仍然可以将其用于不属于 SASS 库的其他关键字,例如 if
、mixin
等。
所以,你仍然可以这样做:
@mixin animation($mykeyframe:mykeyframe) {
@keyframes $mykeyframe {
}
}
body {
@include animation(someframe);
}
这将生成:
body {
@keyframes someframe {}
}
关于sass - 在SASS中编写Mixins时有没有办法逃避@?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16577753/