我想制作一个 CSS 动画,其中时间线基于元素的视图。然而,它不起作用,我已经搜索过但没有结果。
我得到了一个带有容器的页面。在这个容器中,“div.wrapper”是我想要设置动画的东西。 我尝试删除隐藏的溢出并写了这个:
div.wrapper {
width: 50%;
height: 100%;
background-color: red;
animation: fadeIn linear;
animation-timeline: view();
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<div class="container">
<div class="wrapper">
<h2>Sans prise de tête...</h2>
<p class="card"></p>
<btn class="cta"></btn>
</div>
<div class="wrapper">
<h2></h2>
<p class="card"></p>
<btn class="cta">Plus d'infos</btn>
</div>
</div>
有人可以帮忙吗?
正确使用
animation-duration
和其他动画属性。
div.wrapper {
width: 50%;
height: 100%;
background-color: red;
/* animation-name: fadeIn; */
/* animation-duration: 2s; */
/* animation-delay: 0s; */
/* animation-timing-function: ease-in; */
/* animation-iteration-count: 5; */
animation: fadeIn 2s ease-in 5; /* <--- Shorthand of top animation properties*/
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}