Animations
Add animation effects to shapes to control how they appear and behave during a presentation.
Basic Usage
Animations live at the slide level, not on shapes — CT_Shape has no timing
child in the XSD. Each slide exposes an animations array whose entries pair a
shapeId (the target shape's cNvPr id) with an options object:
import { generatePresentation } from "@office-open/pptx";
{
"slides": [
{
"children": [
{
"shape": {
"id": 2,
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "6.6cm",
"textBody": { "text": "Animated shape" }
}
}
],
"animations": [{ "shapeId": 2, "options": { "type": "fade", "duration": 800 } }]
}
]
}
{
children: [
{
shape: {
id: 2,
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "6.6cm",
textBody: { text: "Animated shape" },
},
},
],
animations: [
{ shapeId: 2, options: { type: "fade", duration: 800 } },
],
}
Each animations entry is a { shapeId, options } pair. The shapeId matches
the id set on the target shape's NonVisualDrawingProperties (the cNvPr id),
which you assign via shape.id. The options object carries the animation
preset — the same fields documented in the type-specific sections below.
Animation Types
Entrance Animations (class: "entr", default)
| Type | Description | Supported Directions |
|---|---|---|
appear | Instantly appear | — |
fade | Fade in | — |
fly | Fly in from edge | left, right, up, down |
wipe | Wipe in from edge | left, right, up, down |
dissolve | Dissolve in | — |
split | Split in | horizontal, vertical |
blinds | Blinds effect | horizontal, vertical |
checker | Checkerboard | horizontal, vertical |
randomBars | Random bars | horizontal, vertical |
wheel | Wheel spokes | — |
zoom | Zoom in | — |
cover | Cover from edge | left, right, up, down |
push | Push from edge | left, right, up, down |
strips | Strips from corner | left, right, up, down |
Exit Animations (class: "exit")
Same types as entrance, but with class: "exit":
// entry in slide.animations[]:
{ shapeId, options: { type: "fade", class: "exit", duration: 800 } }
{ shapeId, options: { type: "fly", class: "exit", direction: "right" } }
Emphasis Animations (class: "emph")
emphasisType | Description |
|---|---|
growShrink | Scale up then back |
spin | Full rotation |
colorChange | Change color (requires color) |
transparency | Fade to semi-transparent |
boldFlash | Bold text flash |
wave | Wave effect |
pulse | Pulse effect |
growWithTurn | Grow with rotation |
{ shapeId, options: { class: "emph", emphasisType: "growShrink", duration: 800 } }
{ shapeId, options: { class: "emph", emphasisType: "spin", duration: 1000 } }
{ shapeId, options: { class: "emph", emphasisType: "colorChange", color: "FF0000" } }
Motion Path Animations
pathType | Description |
|---|---|
line | Straight line |
arc | Arc curve |
circle | Circular path |
curve | S-curve |
figureEight | Figure-eight |
bounce | Bounce path |
loop | Loop path |
customPath | Custom SVG path (requires path) |
{ shapeId, options: { pathType: "circle", duration: 1500 } }
{ shapeId, options: { pathType: "customPath", path: "M 0 0 L 100 0 L 100 100 L 0 100 Z", duration: 1200 } }
Media Playback (class: "mediacall")
Trigger audio/video playback on a media shape (a { video } / { audio } child)
with mediaType. The shapeId must point at the media frame:
{ shapeId, options: { class: "mediacall", mediaType: "playVideo", fullScreen: true, showWhenStopped: true } }
{ shapeId, options: { class: "mediacall", mediaType: "playAudio", volume: 80, mute: false } }
| Property | Type | Description |
|---|---|---|
mediaType | "playAudio" | "playVideo" | "play" | Media animation type |
isNarration | boolean | Media is a narration track |
fullScreen | boolean | Play video full-screen |
volume | number | Volume level |
mute | boolean | Mute audio |
showWhenStopped | boolean | Keep the media frame visible when stopped |
Animation Options
| Property | Type | Default | Description |
|---|---|---|---|
type | AnimationType | "appear" | Animation preset type |
class | "entr" | "exit" | "emph" | "mediacall" | "entr" | Animation category |
duration | number | 500 | Duration in milliseconds |
delay | number | 0 | Delay before start in milliseconds |
trigger | AnimationTrigger | "onClick" | How animation is triggered |
direction | AnimationDirection | — | Direction of the animation |
emphasisType | EmphasisType | — | Emphasis animation type (class="emph") |
pathType | PathAnimationType | — | Motion path type |
path | string | — | Custom SVG path string |
speed | number | — | Speed multiplier |
repeatCount | number | — | Number of repetitions |
autoReverse | boolean | false | Auto-reverse after completion |
color | string | — | Target color for colorChange |
pathEditMode | "relative" | "fixed" | "none" | — | Motion path edit mode |
rotationAngle | number | — | Motion path rotation in 1/60000ths of a degree (p:animRot @rAng; passed through raw) |
motionFrom | { x: string; y: string } | — | Motion path start point |
motionRotationCenter | { x: string; y: string } | — | Motion rotation center |
zoomContents | boolean | false | Zoom contents during a scale animation |
Trigger Modes
{ shapeId, options: { type: "fade", trigger: "onClick" } }
{ shapeId, options: { type: "fade", trigger: "withPrevious" } }
{ shapeId, options: { type: "fade", trigger: "afterPrevious" } }