PPTX
切换效果
添加淡入、推入、擦除等幻灯片切换效果
使用幻灯片选项中的 transition 属性在切换幻灯片时添加动画效果。
基本切换
{
"slides": [
{
"children": [],
"transition": { "type": "fade", "speed": "med" }
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [],
transition: { type: "fade", speed: "med" },
},
],
});
幻灯片放映设置
使用 show 选项控制演示文稿播放行为:
{
"show": {
"loop": true,
"useTimings": true
},
"slides": [
{
"children": [
{
"shape": {
"x": "0.0cm",
"y": "0.0cm",
"width": "5.3cm",
"height": "2.6cm",
"textBody": { "text": "幻灯片 1" }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
show: {
loop: true,
useTimings: true,
},
slides: [
{
children: [
{
shape: {
x: "0.0cm",
y: "0.0cm",
width: "5.3cm",
height: "2.6cm",
textBody: { text: "幻灯片 1" },
},
},
],
},
],
});
放映选项
| 属性 | 类型 | 说明 |
|---|---|---|
loop | boolean | 循环放映 |
type | "present" | "browse" | "kiosk" | 放映类型(演讲/浏览/展台) |
showScrollbar | boolean | 显示滚动条(浏览模式) |
restart | number | 重启策略 |
showNarration | boolean | 放映时播放旁白 |
showAnimation | boolean | 放映时显示动画 |
useTimings | boolean | 使用录制的排练时间 |
slideRange | { start: number; end: number } | 限定放映的幻灯片范围 |
penColor | string | 演示笔颜色(srgbClr hex) |
切换类型
淡入
transition: {
type: "fade";
}
推入
transition: { type: "push", direction: "right" }
// direction: "left"(左) | "right"(右) | "up"(上) | "down"(下)
擦除
transition: { type: "wipe", direction: "down" }
覆盖
transition: { type: "cover", direction: "right" }
拆分
transition: { type: "split", orient: "horz", direction: "out" }
// orient: "horz" | "vert"
// direction: "in" | "out"
轮辐
transition: { type: "wheel", spokes: 4 }
溶解
transition: { type: "dissolve", speed: "slow" }
随机
transition: {
type: "random";
}
切换选项
| 属性 | 类型 | 说明 |
|---|---|---|
type | TransitionType | 切换类型 |
speed | "slow" | "med" | "fast" | 切换速度 |
direction | string | 方向(取决于类型) |
orient | "horz" | "vert" | 方向(拆分/百叶窗/棋盘等) |
spokes | number | 轮辐数量(轮辐切换) |
advanceOnClick | boolean | 单击鼠标时切换 |
advanceAfterTime | number | 自动切换间隔(毫秒) |
thruBlk | boolean | 黑场过渡(淡入/剪切) |
startSound | { rId; name?; loop? } | 切换开始时播放的声音 |
stopPreviousSound | boolean | 停止之前播放的声音 |
可用类型
"fade" | "push" | "wipe" | "split" | "blinds" | "checker" | "comb" | "randomBar" | "cover" | "pull" | "strips" | "wheel" | "zoom" | "circle" | "dissolve" | "diamond" | "newsflash" | "plus" | "wedge" | "random" | "cut"
完整示例
{
"slides": [
{
"children": [
{
"shape": {
"x": "2.6cm",
"y": "4.0cm",
"width": "13.2cm",
"height": "2.6cm",
"textBody": { "text": "Welcome" },
"fill": "4472C4"
}
}
],
"transition": { "type": "fade", "speed": "med" }
},
{
"children": [
{
"shape": {
"x": "2.6cm",
"y": "4.0cm",
"width": "13.2cm",
"height": "2.6cm",
"textBody": { "text": "Content Slide" },
"fill": "ED7D31"
}
}
],
"transition": { "type": "push", "direction": "right", "speed": "slow" }
},
{
"children": [
{
"shape": {
"x": "2.6cm",
"y": "4.0cm",
"width": "13.2cm",
"height": "2.6cm",
"textBody": { "text": "Thank You" },
"fill": "70AD47"
}
}
],
"transition": { "type": "wipe", "direction": "down" }
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
slides: [
{
children: [
{
shape: {
x: "2.6cm",
y: "4.0cm",
width: "13.2cm",
height: "2.6cm",
textBody: { text: "Welcome" },
fill: "4472C4",
},
},
],
transition: { type: "fade", speed: "med" },
},
{
children: [
{
shape: {
x: "2.6cm",
y: "4.0cm",
width: "13.2cm",
height: "2.6cm",
textBody: { text: "Content Slide" },
fill: "ED7D31",
},
},
],
transition: { type: "push", direction: "right", speed: "slow" },
},
{
children: [
{
shape: {
x: "2.6cm",
y: "4.0cm",
width: "13.2cm",
height: "2.6cm",
textBody: { text: "Thank You" },
fill: "70AD47",
},
},
],
transition: { type: "wipe", direction: "down" },
},
],
});