PPTX
切换效果
添加淡入、推入、擦除等幻灯片切换效果
使用 Transition 在演示文稿中切换幻灯片时添加动画效果。
基本切换
import { Slide, Transition } from "@office-open/pptx";
new Slide({
children: [],
transition: new Transition({
type: "fade",
}),
});
切换类型
淡入
new Transition({ type: "fade" });
推入
new Transition({ type: "push", dir: "left" });
// dir: "left" | "right" | "up" | "down"
擦除
new Transition({ type: "wipe", dir: "right" });
覆盖
new Transition({ type: "cover", dir: "right" });
拆分
new Transition({ type: "split", dir: "horizontalOut" });
揭示
new Transition({ type: "reveal", dir: "down" });
随机
new Transition({ type: "random" });
切换选项
new Transition({
type: "fade",
duration: 1000, // 持续时间(毫秒)
// advanceOnClick: true, // 单击鼠标时切换(默认:true)
// advanceAfter: 5000, // 5 秒后自动切换
});
完整示例
import {
Presentation,
Slide,
Shape,
Paragraph,
TextRun,
Transition,
Packer,
} from "@office-open/pptx";
import fs from "node:fs";
const pres = new Presentation({
slides: [
new Slide({
children: [
new Shape({
x: 1,
y: 2,
width: 8,
height: 2,
paragraphs: [
new Paragraph({
alignment: "center",
children: [new TextRun({ text: "Welcome", fontSize: 40, bold: true })],
}),
],
}),
],
transition: new Transition({ type: "fade", duration: 800 }),
}),
new Slide({
children: [
new Shape({
x: 1,
y: 2,
width: 8,
height: 2,
paragraphs: [
new Paragraph({
alignment: "center",
children: [new TextRun({ text: "Content Slide", fontSize: 36 })],
}),
],
}),
],
transition: new Transition({ type: "push", dir: "left", duration: 600 }),
}),
new Slide({
children: [
new Shape({
x: 1,
y: 2,
width: 8,
height: 2,
paragraphs: [
new Paragraph({
alignment: "center",
children: [
new TextRun({ text: "Thank You", fontSize: 40, bold: true }),
],
}),
],
}),
],
transition: new Transition({ type: "wipe", dir: "right", duration: 1000 }),
}),
],
});
const buffer = await Packer.toBuffer(pres);
fs.writeFileSync("transitions.pptx", buffer);