[英]How to pause a css animation, and then continue running from the pause point?
我剛剛開始自己深入研究JS,所以肯定有更好的方法可以做到這一點,但是這樣的事情怎么樣 - 演示 (Unprefixed version)。
CSS
#box {
position: relative;
top: 20px;
left: 20px;
width: 100px;
height: 100px;
background: #393939;
animation: move 2s linear infinite;
animation-play-state: running;
}
@keyframes move {
100% {
transform: rotate(360deg);
}
}
JS:
(function () {
var box = document.getElementById('box');
box.onclick = function () {
if (box.style.animationPlayState === "paused") {
box.style.animationPlayState = "running";
} else {
box.style.animationPlayState = "paused";
}
};
})();
根據動畫是否正在運行或暫停,我更改animation-play-state
onclick。
編輯:添加了CSS代碼。
http://jsfiddle.net/zhang6464/MSqMQ/
根據您提供的文章( http://css-tricks.com/restart-css-animation/) ,只需將animation-play-state
css屬性paused
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.