• 회원가입
  • 로그인
  • 구글아이디로 로그인

[DOM_Event] JS - animationend 이벤트 (= onanimationend 속성) - 애니완료이벤트 (= 애니종료이벤트, IE10)

animationend 예제

 

<style> 

#hz {

  margin: 25px;

  width: 400px;

  line-height: 100px;

  text-align:center;

  background: yellow;

  position: relative;

  font-size: 20px;

}


/* Chrome, Safari, Opera */

@-webkit-keyframes hzmove {

  from {top: 0px;}

  to {top: 200px;}

}


@keyframes hzmove {

  from {top: 0px;}

  to {top: 200px;}

}

</style>



<div id="hz" onclick="homzzang()">홈짱닷컴 Homzzang.com [클릭]</div>


<script>

var x = document.getElementById("hz");


// Start the animation with JavaScript

function homzzang() {

  x.style.WebkitAnimation = "hzmove 4s 2"; // Code for Chrome, Safari and Opera

  x.style.animation = "hzmove 4s 2";     // Standard syntax

}


// Chrome, Safari and Opera

x.addEventListener("webkitAnimationStart", homzzangStart);

x.addEventListener("webkitAnimationIteration", homzzangRepeat);

x.addEventListener("webkitAnimationEnd", homzzangEnd);


// 표준

x.addEventListener("animationstart", homzzangStart);

x.addEventListener("animationiteration", homzzangRepeat);

x.addEventListener("animationend", homzzangEnd);


function homzzangStart() {

  this.innerHTML = "animationstart 이벤트 - 이동 시작";

  this.style.backgroundColor = "tomato";

}


function homzzangRepeat() {

  this.innerHTML = "animationiteration 이벤트 - 이동 반복";

  this.style.backgroundColor = "pink";

}


function homzzangEnd() {

  this.innerHTML = "animationend 이벤트 - 이동 종료";

  this.style.backgroundColor = "lightgray";

}

</script> 

 

결과보기


 

animationend 정의

 

 CSS 애니메이션 완료될 때 발생.

 


 

1.

CSS3 animation 참조.

 

2.

관련 이벤트 3가지.

 

animationstart

CSS 애니메이션 시작 때 발생.

 

animationiteration

CSS 애니메이션 반복 때 발생.

 

animationend

CSS 애니메이션 완료 때 발생.


3.

IE10 이상 주요 최신 브라우저 지원.
Chrome, Safari, Opera 접두어: webkit

Firefox 접두어 : moz

 

4.

이벤트확산 : O
취소가능성 : X

이벤트타입 : AnimationEvent

지원 HTML : 

DOM 버전 : Level 3 Events

 

 

 

animationend 구문

 

object.addEventListener("webkitAnimationEnd", homzzang);  // Chrome, Safari, Opera

object.addEventListener("animationend", homzzang); // Standard

 

※ homzzang : 실행함수명.

※ addEventLister() 방식 주의사항 2가지 : (이벤트명에 on 안 붙인. / 실행함수명 뒤에 소괄호 안 붙임)

※ addEventListener() 메서드는 IE8 및 그 이전 브라우저는 지원 안 함. 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
게시물이 없습니다.
목록
찾아주셔서 감사합니다. Since 2012