完成后如何禁用CSS动画

时间:2018-11-09 16:11:41

标签: html css3

我有此Windows 10 Simulator动画,该动画运行蓝色和红色的渐变。该动画从以黑色开始的左侧过渡到具有红色的右侧,然后从左过渡到黑色,即动画结束。我正在尝试找到一种方法,在它运行一次后如何暂停/禁用动画(从左到右然后向左左) 为我的下一个CSS动画腾出空间,但是我不知道如何执行此操作。

是否有一个简单的css属性使动画仅运行一次?

            <html>
    <head>
    <title>Windows 10 Simulator</title>

    <link href="https://fonts.googleapis.com/
    css?family=Noto+Sans|Open+Sans|PT+Sans|
    Raleway|Source+Sans+Pro" rel="stylesheet">
    </head>

    <body>


    <style onload>
    html, body{
    margin: 0;
    padding: 0;

    background-color: #000;
    }

    .wrapper { 
      height: 100%;
      width: 100%;
      left:0;
      right: 0;
      top: 0;
      bottom: 0;
      position: absolute;
    background: linear-gradient(124deg,  #000000, #000000, #0095f0 ,#0095f0, #0095F0, #ff0000, #ff0000, #0095f0);
    background-size: 1800% 1800%;

    animation-iteration-count: 0;  
    animation-fill-mode: forwards;
    animation: rainbow 30s ease infinite;
    }


    @keyframes rainbow { 
        0% {background-position:  0% 0%}
        10%{background-position: 100%% 15%}
        20%{background-position: 100% 30%}
        30%{background-position: 100% 45%}
        40%{background-position: 100% 60%}
        50%{background-position: 100% 85%}
        60%{background-position: 100% 90%}
        70%{background-position: 100% 100%}
        80%{background-position: 100% 90%}
        90%{background-position: 100% 85%}
        80%{background-position: 100% 45%}
        100%{background-position:100% 15%}
        }



      span {
      margin-top: 250px;
      color: #fff;
      font-size: 30px;
      font-family: 'Raleway', sans-serif;
      animation-name: flickerAnimation;
      animation-duration: 5s;
      animation-iteration-count: 1;   
      position: absolute;
      opacity: 0;
      left: 0;
      right: 0;
      text-align: center;
      }

      #message{
      font-size: 10px;
      color: #fff;
      animation-name: alertFade;
      animation-duration: 4s;

      opacity: 0;
      animation-iteration-count: 1000;
      margin-top: 620px;
      }

      span:nth-child(1) {
      animation-delay: 1s;
      animation-duration: 5s;

      }

      span:nth-child(2) {
      animation-delay: 7s;
      animation-duration: 7s;
      }

      span:nth-child(3) {
      animation-delay: 15s;
      }

      span:nth-child(4) {
      animation-delay: 22s;
      }


      @keyframes flickerAnimation{

      0% {opacity: 0;}
      50% {opacity: 1;}
      100% {opacity: .0;}

      }

      @keyframes alertFade{
      0% {opacity: .25}
      50% {opacity: .75}
      100% {opacity: .25}
      }



      </style>
      <div class="wrapper">



      <span>Hello! </span>
      <span>Please Wait While We Setup</span>
      <span>This Will Only Take a Few Seconds</span>
      <span>Just a second...</span>


      <div style="text-align: center;">
      <p id="message" align="center">Please Do Not Turn 
              Off Your Device.</p>
      </div>
      </div>
      </body>
      </html>

1 个答案:

答案 0 :(得分:3)

在.wrapper类中,更改以下动画属性:

animation: rainbow 30s ease infinite; 至: animation: rainbow 30s ease 1;

您已使用animation-iteration-count: 0;将animation-iteration-count设置为0,然后要求其使用rainbow 30s ease infinite;

以下的animation属性无限地播放

希望这会有所帮助!