Skip to content

Animation

Animate viewport channels and control running core animations.

#cy.animate(opts)

// Animate the viewport (pan/zoom) over duration ms
cy.animate(opts: AnimateOptions): this

Animate the viewport (pan/zoom) over duration ms. Element animation is on the collection (eles.animate). Tweens are CPU-canonical; a data write / manual pan mid-animation is not prevented but will be overwritten by the next tick.

Parameters
NameDescription
opts: AnimateOptions

the viewport targets (pan, panBy, zoom, fit, center) plus duration, easing and complete; fit beats center beats panBy beats pan, and panBy with pan throws

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 this

this core, for chaining

Example

cy.animate({ pan: { x: 20, y: 10 }, duration: 100 });
cy.stop(true);
console.log(cy.pan().x); // 20

Example graph and handle setup

#cy.animation(opts)

// Like animate, but returns a handle with play/stop/promise — the viewport counterpart of eles.animation
cy.animation(opts: AnimateOptions): AnimationHandle

Like animate, but returns a handle with play/stop/promise — the viewport counterpart of eles.animation.

Parameters
NameDescription
opts: AnimateOptions

as animate; the animation does not start until play()

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

Example

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

Example graph and handle setup

#cy.animated()

// True while the viewport is animating
cy.animated(): boolean

True while the viewport is animating.

Returns boolean

whether a viewport animation (pan/zoom/fit/center) is running; element animations do not count here — those are eles.animated()

Example

console.log(cy.animated()); // false

Example graph and handle setup

#cy.stop(jumpToEnd?)

// Stop every running viewport animation (animations have no queue)
cy.stop(jumpToEnd?: boolean): this

Stop every running viewport animation (animations have no queue).

Parameters
NameDescription
jumpToEnd: boolean?Default: false

apply each animation's final values instead of freezing the viewport where the tween reached

Returns this

this core, for chaining

Example

cy.animate({ pan: { x: 20, y: 10 }, duration: 100 });
cy.stop(true);
console.log(cy.animated()); // false

Example graph and handle setup

All guides · Alphabetical API index · Read continuously