CSS动画:需要在最后一帧/单词上停止

时间:2015-11-01 23:35:52

标签: css animation

我添加了带CSS动画的旋转文本。我希望动画经历1个循环并冻结最后一帧。使用我当前的代码,动画执行一个循环并以空白帧结束。有关如何纠正此问题的任何建议吗?

    body {} .rw-wrapper {
      width: 80%;
      position: relative;
      margin: 110px auto 0 auto;
      font-family: 'Bree Serif';
      padding: 10px;
    }
    .rw-sentence {
      margin: 0;
      text-align: left;
      text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8);
    }
    .rw-sentence span {
      color: #444;
      font-size: 200%;
      font-weight: normal;
    }
    .rw-words {
      display: inline;
      text-indent: 10px;
    }
    .rw-words-1 span {
      position: absolute;
      opacity: 0;
      overflow: hidden;
      color: #6b969d;
      -webkit-animation: rotateWord 8s 1 forwards;
      -ms-animation: rotateWord 8s 1 forwards;
      animation: rotateWord 8s 1 forwards;
    }
    .rw-words-1 span:nth-child(2) {
      -webkit-animation-delay: 2s;
      -ms-animation-delay: 2s;
      animation-delay: 2s;
      color: #6b889d;
    }
    .rw-words-1 span:nth-child(3) {
      -webkit-animation-delay: 4s;
      -ms-animation-delay: 4s;
      animation-delay: 4s;
      color: #6b739d;
    }
    .rw-words-1 span:nth-child(4) {
      -webkit-animation-delay: 6s;
      -ms-animation-delay: 6s;
      animation-delay: 6s;
      color: #7a6b9d;
    }
    @-webkit-keyframes rotateWord {
      0% {
        opacity: 0;
      }
      2% {
        opacity: 0;
        -webkit-transform: translateY(-30px);
      }
      5% {
        opacity: 1;
        -webkit-transform: translateY(0px);
      }
      17% {
        opacity: 1;
        -webkit-transform: translateY(0px);
      }
      20% {
        opacity: 0;
        -webkit-transform: translateY(30px);
      }
      80% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    @-ms-keyframes rotateWord {
      0% {
        opacity: 0;
      }
      2% {
        opacity: 0;
        -ms-transform: translateY(-30px);
      }
      5% {
        opacity: 1;
        -ms-transform: translateY(0px);
      }
      17% {
        opacity: 1;
        -ms-transform: translateY(0px);
      }
      20% {
        opacity: 0;
        -ms-transform: translateY(30px);
      }
      80% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    @keyframes rotateWord {
      0% {
        opacity: 0;
      }
      2% {
        opacity: 0;
        -webkit-transform: translateY(-30px);
        transform: translateY(-30px);
      }
      5% {
        opacity: 1;
        -webkit-transform: translateY(0px);
        transform: translateY(0px);
      }
      17% {
        opacity: 1;
        -webkit-transform: translateY(0px);
        transform: translateY(0px);
      }
      20% {
        opacity: 0;
        -webkit-transform: translateY(30px);
        transform: translateY(30px);
      }
      80% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    @media screen and (max-width: 768px) {
      .rw-sentence {
        font-size: 18px;
      }
    }
    @media screen and (max-width: 320px) {
      .rw-sentence {
        font-size: 9px;
      }
    }
<section class="rw-wrapper">
  <h2 class="rw-sentence">
		    <span>Test</span>
		    <div class="rw-words rw-words-1">
			    <span>one</span>
			    <span>two</span>
			    <span>three</span>
			    <span>four</span>
		    </div>
	    </h2>
</section>

1 个答案:

答案 0 :(得分:3)

100%的关键帧的不透明度为零。您可以为最后一项工作编写单独的动画,然后使用它。

像这样(我没有添加特定于供应商的关键帧,只有body {} .rw-wrapper { width: 80%; position: relative; margin: 110px auto 0 auto; font-family: 'Bree Serif'; padding: 10px; } .rw-sentence { margin: 0; text-align: left; text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8); } .rw-sentence span { color: #444; font-size: 200%; font-weight: normal; } .rw-words { display: inline; text-indent: 10px; } .rw-words-1 span { position: absolute; opacity: 0; overflow: hidden; color: #6b969d; -webkit-animation: rotateWord 8s 1 forwards; -ms-animation: rotateWord 8s 1 forwards; animation: rotateWord 8s 1 forwards; } .rw-words-1 span:nth-child(2) { -webkit-animation-delay: 2s; -ms-animation-delay: 2s; animation-delay: 2s; color: #6b889d; } .rw-words-1 span:nth-child(3) { -webkit-animation-delay: 4s; -ms-animation-delay: 4s; animation-delay: 4s; color: #6b739d; } @-webkit-keyframes rotateWord { 0% { opacity: 0; } 2% { opacity: 0; -webkit-transform: translateY(-30px); } 5% { opacity: 1; -webkit-transform: translateY(0px); } 17% { opacity: 1; -webkit-transform: translateY(0px); } 20% { opacity: 0; -webkit-transform: translateY(30px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes rotateWord { 0% { opacity: 0; } 2% { opacity: 0; -ms-transform: translateY(-30px); } 5% { opacity: 1; -ms-transform: translateY(0px); } 17% { opacity: 1; -ms-transform: translateY(0px); } 20% { opacity: 0; -ms-transform: translateY(30px); } 80% { opacity: 0; } 100% { opacity: 0; } } @keyframes rotateWord { 0% { opacity: 0; } 2% { opacity: 0; -webkit-transform: translateY(-30px); transform: translateY(-30px); } 5% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } 17% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } 20% { opacity: 0; -webkit-transform: translateY(30px); transform: translateY(30px); } 80% { opacity: 0; } 100% { opacity: 0; } } @media screen and (max-width: 768px) { .rw-sentence { font-size: 18px; } } @media screen and (max-width: 320px) { .rw-sentence { font-size: 9px; } } /* stuff below added by Shomz */ .rw-words-1 span#last { -webkit-animation: rotateLastWord 8s 1 forwards 6s; -ms-animation: rotateLastWord 8s 1 forwards 6s; animation: rotateLastWord 8s 1 forwards 6s; } @keyframes rotateLastWord { 0% { opacity: 0; } 2% { opacity: 0; -webkit-transform: translateY(-30px); transform: translateY(-30px); } 5% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } 17% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } 100% {opacity: 1} },但您也可以添加它们):

&#13;
&#13;
<section class="rw-wrapper">
  <h2 class="rw-sentence">
		    <span>Test</span>
		    <div class="rw-words rw-words-1">
			    <span>one</span>
			    <span>two</span>
			    <span>three</span>
			    <span id="last">four</span>
		    </div>
	    </h2>
</section>
&#13;
$(document).on('click', '#chatanchor', function(e) {
     console.log("Here");
});
&#13;
&#13;
&#13;