美文网首页
css animate暂停

css animate暂停

作者: shaguamayi | 来源:发表于2018-08-01 15:12 被阅读0次
.love {
    display: block;
    width: 100px; height: 100px;
    background: url(https://www.zhangxinxu.com/study/201512/web_heart_animation.png) 0 0 no-repeat;
    background-size: 2900%;
    animation: heart-burst steps(28) 0.8s infinite both;
}
.stop {
    animation-play-state: paused;
}
@keyframes heart-burst {
  0% {
    background-position: 0%;
  }
  100% {
    background-position: 100%;
  }
}
<i id="testImg" class="love"></i>
<p><input type="button" id="testBtn" value="暂停"></p>
var image = document.getElementById("testImg"), 
    button = document.getElementById("testBtn");
    
if (image.classList && image && button) {
    button.onclick = function() {
        if (this.value == '暂停') {
            image.classList.add('stop');
            this.value = '播放';
        } else {
            image.classList.remove('stop');
            this.value = '暂停';
        }
    };
}

来源:https://www.zhangxinxu.com/study/201512/gif-stop-and-play-by-css3-animation.html

相关文章

网友评论

      本文标题:css animate暂停

      本文链接:https://www.haomeiwen.com/subject/sdhrvftx.html