【发布时间】:2022-02-12 21:41:17
【问题描述】:
有什么方法/技巧可以让过渡保持其状态,就像动画填充模式一样?
<style>
#firstdiv {
width: 100px;
height: 100px;
background: red;
animation: firstdivframe 2s;
animation-play-state: paused;
animation-fill-mode: forwards;
}
#firstdiv:hover {
animation-play-state: running
}
@keyframes firstdivframe {
from { background: red; }
to { background: yellow; }
}
#seconddiv {
width: 100px;
height: 100px;
background: red;
transition: background 2s;
}
#seconddiv:hover {
background: yellow;
}
</style>
<div id="firstdiv"></div>
<br />
<div id="seconddiv"></div>
基于上面的代码,我希望 seconddiv 的行为就像 firstdiv 一样,而不使用任何 javascript 代码。当鼠标停止悬停或动画结束时,firstdiv 将保持其状态,而 seconddiv 将始终返回其原始状态。
【问题讨论】:
-
简答:关键帧和动画将完成您的工作。
标签: css css-transitions css-animations