What DOM Interfaces Control SMIL Presentations?
Controlling a running Synchronized Multimedia Integration Language (SMIL) presentation programmatically relies on standard Document Object Model (DOM) interfaces that expose timing, playback, and synchronization hooks. These interfaces allow scripts to dynamically trigger animation elements, pause or seek within timelines, inspect current presentation states, and respond to temporal lifecycle events.
The ElementTimeControl Interface
The primary mechanism defined in the SMIL Timing and Animation
specifications for individual timed elements is the
ElementTimeControl interface. In modern browser
environments, this interface is typically merged directly into host
language elements, such as SVGAnimationElement (e.g.,
<animate>, <animateTransform>,
<set>).
ElementTimeControl exposes four core methods for
programmatic playback:
beginElement(): Starts the element's active duration immediately by adding an unresolved begin instance at the current presentation time.beginElementAt(offset): Schedules the element to begin at a specific offset (in seconds) relative to the moment the method is called.endElement(): Forces the active duration of the element to terminate immediately.endElementAt(offset): Schedules the element to end at a given time offset relative to the invocation.
// Example: Triggering a SMIL animation via ElementTimeControl
const anim = document.getElementById('fadeAnimation');
anim.beginElement(); // Starts immediately
anim.endElementAt(2.5); // Ends after 2.5 secondsGlobal and Container-Level Control Interfaces
While ElementTimeControl operates on individual
animation nodes, container-level control interfaces manage the overall
presentation clock. In SVG documents hosting SMIL timing, the root
SVGSVGElement interface provides global timing
controls:
pauseAnimations(): Suspends the global presentation clock for all active animations in the document fragment.unpauseAnimations(): Resumes clock progression from the paused state.animationsPaused(): Returns a boolean indicating whether presentation timing is currently frozen.getCurrentTime(): Returns the current elapsed time (in seconds) on the document's presentation timeline.setCurrentTime(seconds): Seeks the global timeline to a specific timestamp, recalculating and rendering all active SMIL states at that target time.
const svgRoot = document.querySelector('svg');
// Pause the entire SMIL timeline
svgRoot.pauseAnimations();
// Seek to the 10-second mark and resume
svgRoot.setCurrentTime(10);
svgRoot.unpauseAnimations();The TimeEvent Interface
SMIL defines temporal events dispatched at key moments in an
element's timing lifecycle. These events implement the
TimeEvent interface (extending DOM Level 2
UIEvent/Event) and provide metadata about
playback progression:
beginEvent: Fired when an element begins its active duration.endEvent: Fired when an element ends its active duration.repeatEvent: Fired whenever an element repeats its simple duration, containing adetailproperty indicating the iteration count.
const morphAnim = document.getElementById('morph');
morphAnim.addEventListener('repeatEvent', (event) => {
console.log(`Animation completed iteration: ${event.detail}`);
});SMIL DOM Foundation and Attribute Mutation
In full standalone SMIL implementations (SMIL 2.0/3.0), specific
interfaces such as SMILDocument, SMILElement,
and module-specific extensions (e.g., SMILLayoutElement,
SMILRegionElement) define properties reflecting the SMIL
syntax.
Beyond timing methods, running presentations can also be altered
dynamically using standard DOM Level 2 mutation APIs, such as
setAttribute(), to modify timing attributes
(dur, repeatCount, fill) or
change dynamic sync relationships. Host players recompute runtime
dependencies when dynamic attribute modifications take place.