gpt4 book ai didi

javascript - CSS 动画自动进入默认设置

转载 作者:行者123 更新时间:2023-12-04 07:27:55 26 4
gpt4 key购买 nike

https://jsfiddle.net/t3w1Lqr0/1/
当我运行此代码时,它有时会按预期工作,有时会出现故障并转到 0deg看下面的gif↓
我用它来 electron .
我大部分时间在 jsfiddle 工作但很少在 Electron 中起作用。Electron v13.1.2Chromium v91.0.4472.77Node v14.16.0 enter image description here

最佳答案

您可以纯粹在 CSS 中创建动画并使用 animation-fill-mode: forwards;保留动画的最后一帧。

* {
box-sizing: border-box; margin: 0; padding: 0;
}
html, body { height: 100%; }
body {
display: flex; justify-content: center; align-items: center;
background-color: #eee;
}
div, hr::before {
overflow: hidden; position: absolute;
width: 10rem; height: 5rem;
}
hr {
border-style: solid; border-width: 1.5rem;
border-color: #333; border-radius: 10rem;
width: 10rem; height: 10rem;
}
hr::before {
content: '';
transform-origin: 50% 100%; transform: translateX( -50% );
bottom: 0.25rem; left: 50%;
border-radius: 100% 100% 0.5rem 0.5rem;
width: 0.5rem; height: 4.5rem;
background-color: #ccc;
animation-name: rotate; animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-fill-mode: forwards; /* Force last frame of animation to stay */
}
@keyframes rotate {
0% { transform: translateX( -50% ) rotate( -90deg ); }
100% { transform: translateX( -50% ) rotate( 90deg ); }
}
<div> <hr> </div>

如果你想在你的动画开始播放之前添加一个延迟,就像你的 JavaScript 那样,你可以使用 CSS 属性 animation-delay .

关于javascript - CSS 动画自动进入默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68123878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com