animationDirection 속성은 애니메이션의 방향을 지정하는 데 사용됩니다. 앞으로, 뒤로 또는 교대로 될 수 있습니다.
구문
다음은 −
의 구문입니다.animationDirection 속성 설정 -
object.style.animationDirection = "normal|reverse|alternate|alternate-reverse|initial|inherit"
값
다음은 값입니다 -
| 값 | 설명 |
|---|---|
| 보통 | 애니메이션이 정상적으로 재생되어야 함을 나타내는 기본값입니다. |
| 역방향 | 애니메이션이 반대로 재생되어야 함을 나타냅니다. |
| 대체 | 애니메이션이 홀수 시간에는 정상적으로 재생되고 짝수 시간에는 반대 방향으로 재생되도록 합니다. |
| 대체-역방향 | 교체의 역순으로 홀수 시간에는 역방향으로, 짝수 시간에는 정상 방향으로 애니메이션을 재생합니다. |
| 초기 | 이 속성을 초기 값으로 설정하는 경우 |
| 상속 | 상위 요소에서 이 속성을 상속합니다. |
예시
animationDirection 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 50px;
height: 80px;
background: skyblue;
position: relative;
animation: high 5s infinite;
z-index:-1;
animation-direction:normal;
}
@keyframes high {
0% {left: 0px; top: 0px;}
25% {background-color: lightblue; left: 0px; top: 0px;}
50% {background-color: lightgreen; left: 550px; top: 80px;}
75% {background-color: lightblue; left: 0px; top: 80px;}
100% {left: 0px; top: 0px;}
}
</style>
<script>
function changeDir(){
document.getElementById("DIV1").style.animationDirection="alternate-reverse"
}
</script>
</head>
<body>
<h1>animationDirection property example</h1>
<div id="DIV1"></div>
<p>Change the animation direction of the div by clicking the below button</p>
<button onclick="changeDir()">CHANGE DIRECTION</button>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

애니메이션이 진행되면서 대각선 오른쪽으로 이동합니다 -

CHANGE DIRECTION을 클릭하면 먼저 시작점에서 내려간 다음 역방향으로 이동합니다 -
