Nearby lessons
8 of 14JavaScript HTML DOM – Animation
📌 What is DOM Animation?
With JavaScript, you can create simple animations by changing the position or style of an HTML element repeatedly using setInterval() or requestAnimationFrame(). This helps make your website more interactive and visually engaging.
🚀 Moving an Element (Basic Animation)
This example shows how to move a box to the right using setInterval(). The style.left property changes every few milliseconds, giving the effect of motion.
Code Example
PREVIEW READY
⚡ Smoother Animation with requestAnimationFrame()
requestAnimationFrame() is a better way to animate because it tells the browser to optimize performance and rendering. It's smoother and more efficient than setInterval().
Code Example
PREVIEW READY
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2
Keep Going!JavaScript DOM Events