保持动画播放,直到在CSS的UNDOVER上完成

发布于 2025-01-29 17:18:09 字数 317 浏览 0 评论 0原文

因此,我有一个制作动画的代码块:

.c:hover{
    animation: rotate 1s ease;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    } to {
        transform: rotate(360deg);
    }
}

基本上,我希望动画即使在undover之后继续播放,直到结束

才能提供帮助?

So i have this block of code that makes an animation:

.c:hover{
    animation: rotate 1s ease;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    } to {
        transform: rotate(360deg);
    }
}

Basically i want the animation to keep playing even after unhover until it ends

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2025-02-05 17:18:09

我发现了解决方案,我使用JavaScript在时间过去后删除动画。

const animated = document.getElementById('c');

animated.onmouseenter = () => {
  // Need to remove the animation after its done, otherwise
  // It won't play again when the mouse is hovering on the element.
  setTimeout(() => animated.style.animation = '', 1000);

  animated.style.animation = 'rotate 1s ease';
}

I figured out the solution, I used JavaScript to remove the animation after the time has passed.

const animated = document.getElementById('c');

animated.onmouseenter = () => {
  // Need to remove the animation after its done, otherwise
  // It won't play again when the mouse is hovering on the element.
  setTimeout(() => animated.style.animation = '', 1000);

  animated.style.animation = 'rotate 1s ease';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文