【发布时间】:2022-01-25 01:33:26
【问题描述】:
我有一个元素,动画在开始时开始一次,并且在悬停时无限运行动画。
当鼠标熄灭时,无限动画停止但初始重新运行,如何防止?
这是一个例子,我不希望鼠标熄灭时重新运行 kf-initial 动画。
谢谢!
.foo {
margin: auto;
margin-top: 100px;
padding: 1em;
width: fit-content;
border: solid 1px black;
background: red;
color: white;
font-size: 2em;
/* The initial animation */
animation: kf-initial 2s;
}
.foo:hover {
/* The infinite animation */
animation: kf-hover 10s infinite;
}
@keyframes kf-initial {
from {transform: scale(0.2)}
to {transform: scale(1)}
}
@keyframes kf-hover {
100% {transform: rotate(1turn)}
}
<div class="foo">
Hello world
</div>
【问题讨论】:
标签: html css css-animations