RAF는 그럼 뭐야?
RAF는 Request Animation Frame 의 약자. 렌더링 되기전에 수행되어야 하는 콜백을 지정하는 Web API 다.
<body>
<button>RequestAnimationFrame</button>
<script>
const button = document.querySelector('button');
button.addEventListener('click', (event) => {
requestAnimationFrame(() => {
document.body.style.backgroundColor = 'beige';
});
requestAnimationFrame(() => {
document.body.style.backgroundColor = 'orange';
})
requestAnimationFrame(() => {
document.body.style.backgroundColor = 'red';
})
});
</script>
</body>Last updated