【问题标题】:I want my keyframe animation to restart after some time我希望我的关键帧动画在一段时间后重新启动
【发布时间】:2020-02-27 11:27:10
【问题描述】:

场景:

我有一个动画,当我的背景视频变得非常亮时,我的文字会变黑。

问题:

在背景视频切换回开头后,文本保持黑色。如何重新设置?

目标:

我希望我的 keyframe 动画在几秒钟后重新启动。

问题:

有解决办法吗?

我的代码: HTML:

    <div class="header-text">
    <h1 class="head-text">Rico Dijkstra</h1>
    <h2 class="head-desc">Front-end</h2>
</div>

CSS:

.header-text {
    display: flex;
    flex-direction: column;
    float: right;
    text-align: right;
    align-content: center;
    justify-content: center;
}

.head-text {
    font-family: 'Lato', ;
    color: white;
    float: right;
    font-size: 4rem;
    animation-name: color-swap;
    animation-duration: 3s;
    animation-delay: 4.5s;
    animation-fill-mode: forwards; 
}
.head-desc {
    font-family: 'Lato', ;
    color: white;
    float: right;
    font-size: 3rem;
    animation-name: color-swap;
    animation-duration: 3s;
    animation-delay: 4.5s;
    animation-fill-mode: forwards; 
    margin-top: 0;
}

@keyframes color-swap {
    from {color: white;}
    to {color: black}
  }

【问题讨论】:

    标签: css-animations reset keyframe seconds


    【解决方案1】:

    你可以用 jQuery SetInterval 试试这个 为此,您不需要在开头包含动画 css CSS:

    .header-text {
        display: flex;
        flex-direction: column;
        float: right;
        text-align: right;
        align-content: center;
        justify-content: center;
    }
    
    .head-text {
        font-family: 'Lato', ;
        color: white;
        float: right;
        font-size: 4rem;
    }
    .head-desc {
        font-family: 'Lato', ;
        color: white;
        float: right;
        font-size: 3rem;
        margin-top: 0;
    }
    @keyframes color-swap {
        from {color: white;}
        to {color: black}
    
    

    jquery

    <script
      src="https://code.jquery.com/jquery-3.4.1.min.js"
      integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
      crossorigin="anonymous"></script>
    <script>
    $(document).ready(function(){
      setInterval(function(){ 
       $(".head-text .head-desc").css({
        "animation-name":"color-swap",
        "animation-duration": "3s",
        "animation-fill-mode": "forwards"})
      }, 3000);
    }
    </script>
    

    【讨论】:

    • 我编辑代码。请检查控制台..有什么错误吗??
    • 是的,我修复了一个错误,但它仍然没有工作。它不再给出错误了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2023-03-04
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多