animationPlayState 속성은 실행 중인지 일시 중지되었는지 여부에 관계없이 애니메이션 상태를 설정하거나 가져오는 데 사용됩니다. 이것은 애니메이션을 토글할 때 유용합니다.
구문
다음은
의 구문입니다.animationPlayState 속성 설정 -
object.style.animationPlayState = "running|paused|initial|inherit"
값
다음은 값입니다 -
| Sr.No | 값 및 설명 |
|---|---|
| 1 | 실행 중 애니메이션이 현재 실행 중이고 기본값임을 지정합니다. |
| 2 | 일시중지됨 애니메이션을 지정하기 위해 일시 중지됩니다. |
| 3 | 초기 이 속성을 초기 값으로 설정합니다. |
| 4 | 상속 상위 속성 값을 상속합니다. |
예시
animationPlayState 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 70px;
height: 30px;
border: 3px solid brown;
box-shadow: 0 20px 0 -3px orchid;
z-index:-1;
position: relative;
animation: move 5s infinite;
animation-play-state: play;
}
@keyframes move {
from {top: 0px; }
to {top: 400px;}
}
</style>
<script>
function stateToggle(){
document.getElementById("DIV1").style.animationPlayState="paused";
document.getElementById("Sample").innerHTML="The animation is now paused";
}
</script>
</head>
<body>
<div id="DIV1"></div>
<p>Click the below button to toggle the above animation state</p>
<button onclick="stateToggle()">CHANGE STATE</button>
<p id="Sample"></p>
</body>
</html> 출력
이것은 상자가 위에서 아래로 이동할 때 다음과 같은 출력을 생성합니다 -

CHANGE STATE -
를 클릭하면
