![](/img/trans.png)
[英]Playing CSS animation not playing after adding javascript class when other class removed
[英]Always playing css animation when adding/removing class from div
目前,我通過添加/刪除 class ( playing
)來移動 div,效果很好。 現在我希望這更流暢,並考慮添加一些 css 動畫。 問題是,我不明白如何添加一個 animation,當我刪除或添加這個 class 時,它正在播放。 這甚至可能嗎?
.description-container {
position: absolute;
margin-top: -11%;
}
.description-container.playing {
margin-top: 0%;
}
我嘗試了從上到下的過渡(將播放 class 添加到我的 div 的結果),但它沒有用:
.description-container.playing {
animation: top-to-bottom 1s ease-in forwards;
}
@keyframes top-to-bottom {
100% {
margin-top: 0%;
}
}
我怎樣才能做到這一點?
對於動畫,您可以使用 CSS 屬性transition
。
看看這里。
在您的示例中,您可以使用類似
.description-container {
position: absolute;
margin-top: -11%;
transition: margin-top 5s linear;
}
.description-container.playing {
margin-top: 0%;
}
margin-top
變化linear
速度曲線
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.