【发布时间】:2019-10-25 21:40:03
【问题描述】:
我正在尝试使用图像为加载图标设置动画。我想要实现的是让图像从左到右无限地在两种颜色之间动画。这是在 Angular 7 中完成的。我是动画新手,但据我所知,我可以用 CSS 动画解决这个问题。
我想要的是类似于下面的示例。只有我希望灰度消失到右侧,而不是灰度我想选择两种不同的颜色。
感谢所有帮助!
body {
margin: 0;
}
.effect {
position: relative;
}
.effect-dup {
filter: grayscale(100%);
position: absolute;
overflow: hidden;
top: 0;
left: 0;
width: 0;
animation: width 1s ease-in-out;
animation-fill-mode: forwards;
}
@keyframes width {
from {
width: 0;
}
to {
width: 100%;
}
}
<div class="effect">
<img src="https://placeimg.com/640/480/nature" />
<div class='effect-dup'><img src="https://placeimg.com/640/480/nature" /></div>
</div>
<div class="effect">
<img src="https://placeimg.com/640/480/tech" />
<div class='effect-dup'>
<img src="https://placeimg.com/640/480/tech" />
</div>
</div>
【问题讨论】:
-
把
filter: grayscale(100%)改成你想要的filter... -
您可以使用 CSS 动画,也可以使用基于 Angular 的动画:angular.io/guide/animations。有选择总是很高兴:)
-
@HereticMonkey 感谢您的快速回复!因此,假设我已经设法获得了我想要的过滤器。然后如何在动画中的两个过滤器之间进行切换?
-
它已经动画化了无过滤器和过滤器之间的变化。所以给初始状态添加一个过滤器(
.effect)。
标签: css angular sass css-animations