-
Web animations API 사용하기 (animate)JavaScript 2023. 12. 11. 20:26
웹 애니메이션을 별도의 라이브러리 설치 없이 사용할 수 있다.
내장된 Web api를 사용하여 간단한 애니메이션을 구현할 수 있다.
- HTML
<div> <h1>title</h1> <p class="phrase">lorem ippsum</p> </div>- CSS
.phrase { background: #ff99ff; text-align: center; padding: 10px; }- Javascript
const tag = document.querySelector('.phrase'); tag.addEventListener('click', () => { tag.animate( [ {transform: 'translateY(0px)'}, {transform: 'translateY(15px)'}, {transform: 'translateY(0px)'}, ], { duration: 1500, iterations: Infinity, direction: 'normal', easing: 'ease', }, ); });p태그를 클릭하면, 애니메이션이 실행되는 것을 확인할 수 있다.
⛈ 참고 자료
https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API
Web Animations API - Web APIs | MDN
The Web Animations API allows for synchronizing and timing changes to the presentation of a Web page, i.e. animation of DOM elements. It does so by combining two models: the Timing Model and the Animation Model.
developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/API/Element/animate
Element: animate() method - Web APIs | MDN
The Element interface's animate() method is a shortcut method which creates a new Animation, applies it to the element, then plays the animation. It returns the created Animation object instance.
developer.mozilla.org
'JavaScript' 카테고리의 다른 글
브라우저 window.navigation 객체로 히스토리 관리하기 (1) 2024.04.07 자바스크립트 primitive types은 garbage collecting될까? (0) 2024.01.14 사이트에서 나가시겠습니까? 묻기 (1) 2023.11.12 try catch의 함정 (0) 2023.11.05 await와 then 함께쓰기? (0) 2023.10.29