gpt4 book ai didi

css - Sass Keyframes 动画混合生成无效的 CSS

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:37 25 4
gpt4 key购买 nike

我有以下关键帧混合,但它似乎生成了无效的 CSS:

@mixin keyframes($animationName)
{
@-webkit-keyframes $animationName {
@content;
}
@-moz-keyframes $animationName {
@content;
}
@-o-keyframes $animationName {
@content;
}
@keyframes $animationName {
@content;
}
}

@include keyframes(icon-one) {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}

这是输出:

@-webkit-keyframes $animationName {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
@-moz-keyframes $animationName {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
@-o-keyframes $animationName {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
@keyframes $animationName {
0% {
opacity: 1;
}
33% {
opacity: 0;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}

它没有使用 icon-one 的关键帧名称,而是写出 $animationName

最佳答案

您需要对关键帧名称的变量使用字符串插值。你的关键帧 mixin 需要这样写:

@mixin keyframes($animationName)
{
@-webkit-keyframes #{$animationName} {
@content;
}
@-moz-keyframes #{$animationName} {
@content;
}
@-o-keyframes #{$animationName} {
@content;
}
@keyframes #{$animationName} {
@content;
}
}

请注意 keyframes mixin that comes with Compass does this .

GitHub 上有一个问题表明 interpolation was not required in certain versions of Sass (possibly limited to 3.3.x) .但是,Sass 的作者认为这是一个错误:

The previous behavior was a bug. Variables should never have been allowed uninterpolated in any directives.

关于css - Sass Keyframes 动画混合生成无效的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27438911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com