gpt4 book ai didi

css - 防止@keyframe变换: rotate() from skipping its initial transform: rotate() value at the end of its animation cycle

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:37 26 4
gpt4 key购买 nike

我试图将元素从其起始旋转点旋转 360 度,而不是从 0deg。例如,如果起点是 90deg,它会从 90deg 旋转到 90deg(整圈)。

我的目标是使用简单的@keyframes 动画来旋转元素,而不是使用 JS 进行动画处理。我目前正在通过 JS 设置元素的初始转换,如下所示:

this.$element.css({
transform: 'rotate' + startingDegreePosition + 'deg)'
});

问题在于,当动画开始时,它仅在其起始位置和关键帧的结束位置之间进行动画处理。我希望使用 1turn 值可以解决这个问题,但它似乎并不像我预期的那样工作。我希望它与起点成 360 度。我的感觉是这是不可能的,但我想我还是会把它扔掉。

示例代码:

http://jsbin.com/jayedi/1/edit

您可以在示例中看到它将从起点旋转到 360deg 然后再次切回到起点,跳过最后的 90 度。我正在寻找从起点平滑的 360 度旋转。

最佳答案

对于 90 度,您需要从 -90 度旋转到 +90 度。我知道您想使 90deg 动态而不是固定值。在这种情况下,您还必须更新您的 @keyframes rotate css。这是一点点工作;您可以在单独的 css 文件中定义关键帧 css,并通过 js 读取 css 文件内容,并在运行时使用 js 修改其内容。这是一个关于如何从 js 动态更改 @keyframe css 的 jsfiddle 链接:http://jsfiddle.net/russelluresti/RHhBz/3/

div {
width: 10px;
height: 40px;
background-color: thistle;
animation: rotate 2s linear infinite;
}
@keyframes rotate {
/* to { transform: rotateZ(1turn); } */
from {
transform: rotateZ(-90deg);
}
to {
transform: rotateZ(90deg);
}
}
/*///*/

html,
body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>

<body>
<div style="transform: rotateZ(90deg)"></div>
</body>

</html>

关于css - 防止@keyframe变换: rotate() from skipping its initial transform: rotate() value at the end of its animation cycle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30655952/

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