loading code fetching the highlighted snippet
useAnimationFrame(cb) calls cb(time, delta) every frame and returns a cleanup. Use time to drive trig functions and you get smooth, perpetual motion without component re-renders.
time (ms since the loop started) and delta (ms since last frame). Driving rotations from Math.sin(time / 1000) gives you smooth oscillation that is frame-rate independent.element.style.transform skips Svelte's reactivity — perfect
when you'd otherwise trigger 60 component re-renders a second. Use this pattern for canvas
/ WebGL drivers too.$effect and return the cleanup. Svelte runs the effect after
mount, and tears down the loop when the component unmounts — no leaked rAF callbacks even
during fast HMR.