Which method is commonly used to create smooth animations in JavaScript?
D
requestAnimationFrame()
Analysis & Theory
`requestAnimationFrame()` is the best method for smooth, optimized animations in JavaScript.
What does `element.style.transform = 'translateX(100px)'` do?
A
Moves the element vertically
C
Moves the element 100px to the right
D
Changes the background color
Analysis & Theory
`translateX(100px)` moves the element 100 pixels to the right.
What is the purpose of `setInterval()` in animations?
B
It updates styles continuously at a fixed time interval
D
It removes elements from the DOM
Analysis & Theory
`setInterval()` repeatedly executes a function, useful for basic animation loops.
How can you stop an animation created with `setInterval()`?
Analysis & Theory
`clearInterval()` stops the interval loop using its ID.
Which CSS property can be animated using JavaScript?
Analysis & Theory
JavaScript can animate most numeric CSS properties including `top`, `left`, `opacity`, etc.
What is the default frame rate of `requestAnimationFrame()`?
Analysis & Theory
`requestAnimationFrame()` typically runs at 60 frames per second for smooth animations.
Which method provides better performance for animations?
B
requestAnimationFrame()
Analysis & Theory
`requestAnimationFrame()` is optimized by the browser and syncs with screen refresh rate.
How do you move a box to the right continuously?
C
Increment the `left` style inside a loop
D
Use `innerHTML` repeatedly
Analysis & Theory
You move a box by increasing its `left` or `transform` style over time.
What unit is commonly used for animating position?
Analysis & Theory
You can use `px`, `%`, `em`, depending on the layout and desired effect.
Which event is NOT directly related to animation?
Analysis & Theory
`onclick` is a general event; the others are animation-specific events in CSS/JS.