Skip to content

eles.animation(opts)

eles.animation — Collection > Animation. Cytoscape.js signatures, parameters and return contract.

eles.animation — Collection › Animation

Preview · Collection › Animation

Read in the complete API reference · All API members

// Build an animation for these elements without starting it
eles.animation(opts: AnimateOptions): AnimationHandle

Build an animation for these elements without starting it.

Parameters
NameDescription
opts: AnimateOptions

the tween targets (position, style, or compound collapsed state) plus duration, delay, easing and complete

Fields of opts
NameDescription
style: Record<string, string | number>?
position: Partial<Position>?
collapsed: boolean?

Target the collapsed state of compound parents. This is an element-only animation channel and may be combined with timing options, but not with other style, position, or viewport targets.

pan: Position?

viewport targets (core.animate)

panBy: Position?

viewport target: pan by a delta rather than to an absolute position. Resolved against the pan at creation time, so a manual pan afterwards does not move the target. Throws alongside pan — the two spell the same channel. Core-only: an element animation ignores it.

zoom: number?
fit: { eles?: unknown; boundingBox?: { x1: number; y1: number; x2?: number; y2?: number; w?: number; h?: number; }; padding?: number; }?

viewport target: animate to the viewport that fits the given elements (or an explicit model-space box). Resolved to pan/zoom when the animation is created.

center: { eles?: unknown }?

viewport target: animate the pan that centers the given elements

duration: number?
easing: string?

A named easing, cubic-bezier(), linear() or spring(bounce). For a spring, duration is the perceptual duration and the animation runs on past it to settle, so its total length is longer (see durationMs).

delay: number?
complete: () => void?
Returns AnimationHandle

the handle; nothing runs until play()

Example

const handle = eles.animation({ position: { x: 20, y: 10 }, duration: 1 });
await handle.play();
console.log(handle.progress()); // 1

Example graph and handle setup