Examples
Practical examples. Live demos.
Pick an example to open it full screen, with the live preview and its source side by side.
Pick an example to open it full screen, with the live preview and its source side by side.
SMIL as builders: animateSvg pulses the sun, animateTransformSvg orbits the planet. A dynamic dur sets the speed.
import 'nuclo' let svg: SVGSVGElement | undefined let paused = false let speed = 1 const setSpeed = (next: number) => { speed = next update() } // SMIL elements are builders too: animateSvg drives one attribute, // animateTransformSvg a transform. A modifier function receives the // element, here to keep the <svg> for pauseAnimations(). export const Orbit = () => div( svgSvg( { viewBox: '0 0 200 200', width: '200', height: '200' }, (el: SVGSVGElement) => { svg = el }, circleSvg({ cx: 100, cy: 100, r: 70, fill: 'none', stroke: '#eee', 'stroke-width': 1.5, 'stroke-dasharray': '3 5', }), // The sun pulses. circleSvg( { cx: 100, cy: 100, r: 22, fill: '#ff3f00' }, animateSvg({ attributeName: 'r', values: '22;26;22', dur: '2s', repeatCount: 'indefinite', }), ), // The planet orbits; its moon spins around it. gSvg( animateTransformSvg({ attributeName: 'transform', type: 'rotate', from: '0 100 100', to: '360 100 100', repeatCount: 'indefinite', dur: () => `${6 / speed}s`, // dynamic: update() changes the speed }), circleSvg({ cx: 170, cy: 100, r: 10, fill: '#2563eb' }), gSvg( animateTransformSvg({ attributeName: 'transform', type: 'rotate', from: '0 170 100', to: '360 170 100', dur: '1.5s', repeatCount: 'indefinite', }), circleSvg({ cx: 188, cy: 100, r: 4, fill: '#ff8a00' }), ), ), ), div( { style: { display: 'flex', gap: '8px', justifyContent: 'center' } }, button(() => (paused ? 'Play' : 'Pause'), { onClick: () => { paused = !paused paused ? svg?.pauseAnimations() : svg?.unpauseAnimations() update() }, }), button('Slower', { onClick: () => setSpeed(Math.max(0.25, speed / 2)) }), button(() => `${speed}×`, { onClick: () => setSpeed(1) }), button('Faster', { onClick: () => setSpeed(Math.min(8, speed * 2)) }), ), )