css - 当 @include 一个 mixin 时,它引用了一个之前传递的变量
问题描述
所以我定义了这个mixin。
@mixin bgReveal($color) {
animation-name: bgReveal;
animation-duration: 350ms;
animation-fill-mode: both;
animation-timing-function: ease-in-out;
@keyframes bgReveal {
0% {background: transparent;}
100% {background: $color;}
}
}
现在当我这样做时
.profile-card {
@include bgReveal($color1);
}
.profile-mail {
@include bgReveal($color2);
}
profile-card
和profile-mail
组件都将其背景设置为color2
. 这里可能是什么问题?
解决方案
似乎问题出在动画名称中:
@keyframes bgReveal {
0% {background: transparent;}
100% {background: $color;}
}
您已经创建了两次相同的动画(因为您已经包含了两次 mixin),名称相同,但背景颜色不同。根据 CSS 规则,如果您有 2 个相同的属性,则最后一个将处于活动状态。因此,如果您有 2 个具有相同名称的关键帧动画,则只会应用最后一个。
如果你只是在你的 mixin 中传递一个唯一的动画名称,它就会正常工作!
@mixin bgReveal($color, $anim-name) {
animation-name: $anim-name;
animation-duration: 350ms;
animation-fill-mode: both;
animation-timing-function: ease-in-out;
@keyframes #{$anim-name} {
0% {background: transparent;}
100% {background: $color;}
}
}
.profile-card {
@include bgReveal($color1, redAnim);
}
.profile-mail {
@include bgReveal($color2, greenAnim);
}
推荐阅读
- android - Android ImageView 和自定义图像视图
- python - 在 Django 视图中等待另一个请求
- javascript - 使用 vscode 和 powershell 时出现“未定义的不和谐”
- python - 如何找到百分比变化值的同一行中的值
- c++ - 使用 C++ 在 OpenGL 中移动自动旋转的 3d 多边形
- java - 无法从 ViewHolder (RecycleView) 调用 Adapter(onBindViewHolder) 中的方法
- sql - 在 Redshift 中查找给定表名的模式名称
- android - 应用被终止时显示本地通知 - Xamarin.Android
- javascript - 如何呈现 Spotify 播放列表数据?
- memory-management - VSCode 工作区单独的扩展列表