动画返回到初始关键帧。

huangapple go评论81阅读模式
英文:

Animation returns to the beginning keyframe

问题

I want my CSS animation to run through once and stop at the final keyframe, but right now it just returns to the first keyframe and the animation stops. The animation consists of a title heading that fills up with color through time.

我希望我的CSS动画只运行一次并停在最后的关键帧,但现在它只返回到第一个关键帧然后停止。动画包括一个标题,通过时间逐渐填充颜色。

I am using this code in the Elementor plugin in WordPress.

我在WordPress的Elementor插件中使用这段代码。

Could anyone tell me what I'm doing wrong?

有人能告诉我我做错了什么吗?

英文:

I want my CSS animation to run through once and stop at the final keyframe, but right now it just returns to the first keyframe and the animation stops. The animation consists of a title heading that fills up with color through time.

I am using this code in the Elementor plugin in WordPress.

Could anyone tell me what I'm doing wrong?

<style>
    :root{
        --myText : 'HELLO';
        --textColor: #EDC300;
        --textStroke: 2px;
        --anDuration: 8s;
    }
    selector{
        -webkit-text-stroke: var(--textStroke) var(--textColor);
        display: table;
        width: -moz-fit-content;
        width: -webkit-fit-content;
        width: fit-content;
        text-align: center;
        margin: 0 auto
    }
    selector .elementor-heading-title::before{
        content: var(--myText);
        color: var(--textColor);
        position: absolute;
        top: 0;
        width: 0%;
        height: 100%;
        text-align: left;
        overflow: hidden;
        white-space: nowrap;
        border-right: var(--textStroke) solid var(--textColor);
        -webkit-animation:animateX var(--anDuration) linear 1;
        -webkit-animation-fill-mode: forwards;
        animation:animateX var(--anDuration) linear 1;
        animation-fill-mode: forwards;
    }

    @-webkit-keyframes animateX{
       0%,10%,100%{
            width:0%;
        }
       70%, 90%{
            width: 100%;
        }
    }

    @keyframes animateX{
       0%,10%,100%{
            width:0%;
        }
       70%, 90%{
            width:100%;
        }
    }
</style>

答案1

得分: 1

0% 和 100% 处的动画关键帧是相同的,这会让动画看起来回到了第一帧。我认为从定义0%关键帧的关键帧中移除 100% 将解决这个问题。

英文:

The animation keyframes at 0% and 100% are the same, which would make it seem that the animation had returned to the first frame. I think removing 100% from the keyframe that defines the 0% keyframe, that’ll fix the issue.

答案2

得分: 0

如@Caleb所说,animateX的第一个和最后一个关键帧的宽度为0%;

这意味着在开始时,宽度将为0%,然后执行其他帧,直到最后,其中宽度再次为0%。

解决方案如下:

@keyframes animateX {
    0%, 10%, 90% {
        width: 0%;
    }
    70%, 100% {
        width: 100%;
    }
}

请注意,我更改了关键帧的百分比,以便它在关键帧的100%处以宽度:100%结束。

在@-webkit-keyframes中也是一样的。

英文:

As already said by @Caleb the first and last keyframes of animateX have width: 0%;

This means that at the start, width will be 0%, then it will excute the other frames until the last, where with again is 0%.

The solution would be:

@keyframes animateX{
       0%,10%,90%{
            width:0%;
        }
       70%, 100%{
            width:100%;
        }
    }

Note how i changed the percentajes of the keyframes, so it ends (at 100% of keyframes) with width: 100%

The same in @-webkit-keyframes

huangapple
  • 本文由 发表于 2023年6月6日 10:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定