gsap-plugins by greensock/gsap-skills
npx skills add https://github.com/greensock/gsap-skills --skill gsap-plugins当使用或审查使用 GSAP 插件的代码时应用:注册插件、滚动到、flip/FLIP 动画、可拖拽元素、SVG(DrawSVG、MorphSVG、MotionPath)、文本(SplitText、ScrambleText)、物理、缓动插件(CustomEase、EasePack、CustomWiggle、CustomBounce)或 GSDevTools。ScrollTrigger 有它自己的技能(gsap-scrolltrigger)。
相关技能: 对于核心补间动画使用 gsap-core;对于 ScrollTrigger 使用 gsap-scrolltrigger;对于 React 使用 gsap-react。
每个插件注册一次,以便 GSAP(和打包工具)知道包含它。使用 gsap.registerPlugin() 注册项目中使用的每个插件:
import gsap from "gsap";
import { ScrollToPlugin } from "gsap/ScrollToPlugin";
import { Flip } from "gsap/Flip";
import { Draggable } from "gsap/Draggable";
gsap.registerPlugin(ScrollToPlugin, Flip, Draggable);
动画化滚动位置(窗口或可滚动元素)。用于“滚动到元素”或“滚动到位置”,无需 ScrollTrigger。
gsap.registerPlugin(ScrollToPlugin);
gsap.to(window, { duration: 1, scrollTo: { y: 500 } });
gsap.to(window, { duration: 1, scrollTo: { y: "#section", offsetY: 50 } });
gsap.to(scrollContainer, { duration: 1, scrollTo: { x: "max" } });
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
ScrollToPlugin — 关键配置(scrollTo 对象):
| 选项 | 描述 |
|---|---|
x, y | 目标滚动位置(数字),或 "max" 表示最大值 |
element | 要滚动到的选择器或元素(用于滚动到视图) |
offsetX, offsetY | 距离目标位置的像素偏移量 |
平滑滚动包装器(平滑原生滚动)。需要 ScrollTrigger 和特定的 DOM 结构(内容包装器 + 平滑包装器)。当需要平滑、动量式滚动时使用。请参阅 GSAP 文档进行设置;在 ScrollTrigger 之后注册。DOM 结构如下所示:
<body>
<div id="smooth-wrapper">
<div id="smooth-content">
<!--- 所有您的内容放在这里 --->
</div>
</div>
<!-- position: fixed 的元素可以放在外面 --->
</body>
使用 Flip.getState() 捕获状态,然后应用更改(例如布局或类更改),然后使用 Flip.from() 从前一个状态动画过渡到新状态(FLIP:First, Last, Invert, Play)。当在两个布局状态之间进行动画过渡时使用(列表、网格、展开/折叠)。
gsap.registerPlugin(Flip);
const state = Flip.getState(".item");
// 更改 DOM(重新排序、添加/删除、更改类)
Flip.from(state, { duration: 0.5, ease: "power2.inOut" });
Flip — 关键配置(Flip.from 变量):
| 选项 | 描述 |
|---|---|
absolute | 在翻转期间使用 position: absolute(默认:false) |
nested | 当为 true 时,仅测量第一级子元素(对于嵌套变换更好) |
scale | 当为 true 时,缩放元素以适应(避免拉伸);默认 true |
simple | 当为 true 时,仅动画化位置/缩放(更快,但准确性较低) |
duration, ease | 标准补间选项 |
使元素可通过鼠标/触摸进行拖拽、旋转或投掷。用于滑块、卡片、可重新排序的列表或任何拖拽交互。
gsap.registerPlugin(Draggable, InertiaPlugin);
Draggable.create(".box", { type: "x,y", bounds: "#container", inertia: true });
Draggable.create(".knob", { type: "rotation" });
Draggable — 关键配置选项:
| 选项 | 描述 |
|---|---|
type | "x", "y", "x,y", "rotation", "scroll" |
bounds | 元素、选择器或 { minX, maxX, minY, maxY } 以限制拖拽 |
inertia | true 以启用投掷/动量(需要 InertiaPlugin) |
edgeResistance | 0–1;拖拽超出边界时的阻力 |
cursor | 拖拽期间的 CSS 光标 |
onDragStart, onDrag, onDragEnd | 回调函数;接收事件和目标 |
onThrowUpdate, onThrowComplete | 当惯性激活时的回调函数 |
与 Draggable 配合使用,实现释放后的动量,或跟踪任何对象的任何属性的惯性/速度,以便它可以使用简单的补间动画无缝滑行停止。当使用 inertia: true 时与 Draggable 一起注册:
gsap.registerPlugin(Draggable, InertiaPlugin);
Draggable.create(".box", { type: "x,y", inertia: true });
或跟踪属性的速度:
InertiaPlugin.track(".box", "x");
然后使用 "auto" 继续当前速度并滑行停止:
gsap.to(obj, { inertia: { x: "auto" } });
跨设备标准化指针和滚动输入。用于滑动、滚动方向或自定义手势逻辑,而不像 ScrollTrigger 那样直接绑定到滚动位置。
gsap.registerPlugin(Observer);
Observer.create({
target: "#area",
onUp: () => {},
onDown: () => {},
onLeft: () => {},
onRight: () => {},
tolerance: 10
});
Observer — 关键配置选项:
| 选项 | 描述 |
|---|---|
target | 要观察的元素或选择器 |
onUp, onDown, onLeft, onRight | 当滑动/滚动在该方向上超过容差时的回调函数 |
tolerance | 检测方向前的像素数;默认 10 |
type | "touch", "pointer", 或 "wheel"(默认:"touch,pointer") |
将元素的文本分割成字符、单词和/或行(每个都在其自己的元素中),用于交错或按单元动画。当需要逐字符、逐单词或逐行动画文本时使用。返回一个包含 chars、words、lines(以及当 mask 设置时的 masks)的实例。使用 revert() 恢复原始标记,或让 gsap.context() 恢复。与 gsap.context()、matchMedia() 和 useGSAP() 集成。API:SplitText.create(target, vars)(target = 选择器、元素或数组)。
gsap.registerPlugin(SplitText);
const split = SplitText.create(".heading", { type: "words, chars" });
gsap.from(split.chars, { opacity: 0, y: 20, stagger: 0.03, duration: 0.4 });
// 稍后:split.revert() 或让 gsap.context() 清理恢复
使用 onSplit()(v3.13.0+),动画在每次分割时运行,并在使用 autoSplit 时在重新分割时运行;从 onSplit() 返回一个补间/时间线可以让 SplitText 在重新分割时清理并同步该动画的进度:
SplitText.create(".split", {
type: "lines",
autoSplit: true,
onSplit(self) {
return gsap.from(self.lines, { y: 100, opacity: 0, stagger: 0.05, duration: 0.5 });
}
});
SplitText — 关键配置(SplitText.create 变量):
| 选项 | 描述 |
|---|---|
| type | 逗号分隔:"chars", "words", "lines"。默认 "chars,words,lines"。仅分割需要的内容(例如,如果不使用行,则使用 "words, chars")以提高性能。避免仅分割字符而不分割单词/行,或使用 smartWrap: true 以防止奇怪的行断。 |
| charsClass , wordsClass , linesClass | 每个分割元素上的 CSS 类。附加 "++" 以添加递增的类(例如 linesClass: "line++" → line1, line2, …)。 |
| aria | "auto"(默认), "hidden", 或 "none"。可访问性:"auto" 在分割元素上添加 aria-label,在线/单词/字符元素上添加 aria-hidden,以便屏幕阅读器读取标签;"hidden" 对所有内容隐藏,不向阅读器暴露;"none" 保持 aria 不变。如果必须暴露嵌套的链接/语义,请使用 "none" 加上一个屏幕阅读器专用的副本。 |
| autoSplit | 当为 true 时,在字体加载完成或元素宽度更改(并且行被分割)时恢复并重新分割,避免错误的换行。动画必须在 onSplit() 内部创建,以便它们定位到新分割的元素;从 onSplit() 返回 动画以在重新分割时自动清理和时间同步。 |
| onSplit(self) | 分割完成时(以及如果 autoSplit 为 true,则在每次重新分割时)的回调函数。接收 SplitText 实例。返回一个 GSAP 补间或时间线可以在重新分割时自动恢复/同步该动画。 |
| mask | "lines", "words", 或 "chars"。将每个单元包装在一个具有 overflow: clip 的额外元素中,用于遮罩/显示效果。仅一种类型;在实例的 masks 数组上访问包装器(或如果设置了类,则使用类 -mask)。 |
| tag | 包装器元素标签;默认 "div"。使用 "span" 用于内联(注意:在某些浏览器中,旋转/缩放等变换可能不会在内联元素上渲染)。 |
| deepSlice | 当为 true(默认)时,跨越多行的嵌套元素(例如 <strong>)会被细分,以便行不会垂直拉伸。仅适用于分割行时。 |
| ignore | 要保留不分割的选择器或元素(例如 ignore: "sup")。 |
| smartWrap | 当仅分割 chars 时,将单词包装在 white-space: nowrap 的 span 中,以避免单词中间换行。如果分割了单词或行,则忽略。默认 false。 |
| wordDelimiter | 单词边界:字符串(默认 " ")、正则表达式或 { delimiter: RegExp, replaceWith: string } 用于自定义分割(例如,用于标签的零宽度连接符,或非拉丁语)。 |
| prepareText(text, parent) | 接收原始文本和父元素的函数;在分割前返回修改后的文本(例如,为没有空格的语言插入断行标记)。 |
| propIndex | 当为 true 时,在每个分割元素上添加一个带有索引的 CSS 变量(例如 --word: 1, --char: 2)。 |
| reduceWhiteSpace | 折叠连续空格;默认 true。从 v3.13.0 开始,也尊重换行符,并可以为 <pre> 插入 <br>。 |
| onRevert | 当实例恢复时的回调函数。 |
提示: 仅分割动画化的部分(例如,如果只动画化单词,则跳过字符)。对于自定义字体,在它们加载后分割(例如 document.fonts.ready.then(...))或使用 autoSplit: true 和 onSplit()。为了避免分割字符时的字距调整偏移,使用 CSS font-kerning: none; text-rendering: optimizeSpeed;。避免使用 text-wrap: balance;它可能会干扰分割。SplitText 不支持 SVG <text>。
了解更多: SplitText
使用乱码/故障效果动画化文本。当需要以乱码方式显示或过渡文本时使用。
gsap.registerPlugin(ScrambleTextPlugin);
gsap.to(".text", {
duration: 1,
scrambleText: { text: "New message", chars: "01", revealDelay: 0.5 }
});
通过动画化 stroke-dashoffset / stroke-dasharray 来显示或隐藏 SVG 元素的描边。适用于 <path>, <line>, <polyline>, <polygon>, <rect>, <ellipse>。当需要“绘制”或“擦除”描边时使用。
drawSVG 值: 描述沿路径的描边的可见段(起点和终点位置),而不是“随时间从 A 到 B 动画化”。格式:百分比或长度形式的 "start end"。示例:"0% 100%" = 完整描边;"20% 80%" = 仅在 20% 到 80% 之间的描边(两端有间隙)。补间动画从元素的当前段动画过渡到目标段 —— 例如,gsap.to("#path", { drawSVG: "0% 100%" }) 从当前状态过渡到完整描边。单值(例如 0, "100%")表示起点为 0:"100%" 等同于 "0% 100%"。
必需: 元素必须有可见的描边 —— 在 CSS 中或作为 SVG 属性设置 stroke 和 stroke-width;否则不会绘制任何内容。
gsap.registerPlugin(DrawSVGPlugin);
// 从无到完整描边绘制
gsap.from("#path", { duration: 1, drawSVG: 0 });
// 或显式段:从 0–0 到 0–100%
gsap.fromTo("#path", { drawSVG: "0% 0%" }, { drawSVG: "0% 100%", duration: 1 });
// 仅中间有描边(两端有间隙)
gsap.to("#path", { duration: 1, drawSVG: "20% 80%" });
注意事项: 仅影响描边(不影响填充)。优先使用单段 <path> 元素;多段路径在某些浏览器中可能渲染异常。<use> 的内容无法视觉更改。DrawSVGPlugin.getLength(element) 和 DrawSVGPlugin.getPosition(element) 返回描边长度和当前位置。
了解更多: DrawSVG
通过动画化 d 属性(路径数据)将一个 SVG 形状变形为另一个。起始和结束形状不需要相同数量的点 —— MorphSVG 会转换为三次贝塞尔曲线并根据需要添加点。用于图标到图标的变形、形状过渡或基于路径的动画。适用于 <path>, <polyline>, 和 <polygon>;<circle>, <rect>, <ellipse>, 和 <line> 在内部转换或通过 MorphSVGPlugin.convertToPath(selector | element) 转换(在 DOM 中用 <path> 替换该元素)。
morphSVG 值: 可以是选择器(例如 "#lightning")、元素、原始路径数据(例如 "M47.1,0.8 73.3,0.8..."),或者对于多边形/折线,可以是点字符串(例如 "240,220 240,70 70,70 70,220")。对于完整配置,使用对象形式,其中 shape 是唯一必需的属性。
gsap.registerPlugin(MorphSVGPlugin);
// 如果需要,首先将基本形状转换为路径:
MorphSVGPlugin.convertToPath("circle, rect, ellipse, line");
gsap.to("#diamond", { duration: 1, morphSVG: "#lightning", ease: "power2.inOut" });
// 对象形式:
gsap.to("#diamond", {
duration: 1,
morphSVG: { shape: "#lightning", type: "rotational", shapeIndex: 2 }
});
MorphSVG — 关键配置(morphSVG 对象):
| 选项 | 描述 |
|---|---|
| shape | (必需。) 目标形状:选择器、元素或原始路径字符串。 |
| type | "linear"(默认)或 "rotational"。Rotational 使用角度/长度插值,可以避免变形中途的扭结;当线性变形看起来不对时尝试使用。 |
| map | 如何匹配段:"size"(默认)、"position" 或 "complexity"。当起始/结束段不对齐时使用;如果都不起作用,分割成多个路径并分别变形。 |
| shapeIndex | 偏移起始路径中的哪个点映射到结束路径的第一个点(避免形状“交叉”或反转)。对于单段路径为数字;对于多段路径为数组(例如 [5, 1, -8])。负值反转该段。使用 shapeIndex: "log" 一次以记录自动计算的值,然后将数字/数组粘贴到补间中。findShapeIndex(start, end)(单独的实用工具)提供了一个交互式 UI 来找到一个好的值。仅适用于闭合路径。 |
| smooth | (v3.14+)。添加平滑点。数字(例如 80)、"auto" 或对象:`{ points: 40 |
| curveMode | 布尔值(v3.14+)。插值控制柄角度/长度而不是原始 x/y 以避免曲线上的扭结。如果变形中途有扭结,请尝试。 |
| origin | type: "rotational" 的旋转原点。字符串:"50% 50%"(默认)或 "20% 60%, 35% 90%" 用于不同的起始/结束原点。 |
| precision | 输出路径数据的小数位数;默认 2。 |
| precompile | 预计算路径字符串的数组(或使用 precompile: "log" 一次,从控制台复制)。跳过昂贵的启动计算;用于非常复杂的变形。仅适用于 <path>(首先转换多边形/折线)。 |
| render | 每次更新时调用的函数(rawPath, target) —— 例如,绘制到画布。RawPath 是一个段数组(每个段 = 交替的 x,y 三次贝塞尔坐标数组)。 |
| updateTarget | 当使用 render 时(例如仅画布),设置 updateTarget: false 以便原始 <path> 不被更新。MorphSVGPlugin.defaultUpdateTarget 设置默认值。 |
实用工具: MorphSVGPlugin.convertToPath(selector | element) 将 circle/rect/ellipse/line/polygon/polyline 转换为 DOM 中的 <path>。MorphSVGPlugin.rawPathToString(rawPath) 和 stringToRawPath(d) 在路径字符串和原始数组之间转换。插件在目标上存储原始的 d(例如,用于补间回:morphSVG: "#originalId" 或同一元素)。
提示: 对于扭曲或反转的变形,设置 shapeIndex(使用 "log" 或 findShapeIndex())。对于多段路径,shapeIndex 是一个数组(每段一个值)。仅在第一帧较慢时预编译;它不能修复补间期间的卡顿(如果需要,简化 SVG 或减小尺寸)。
了解更多: MorphSVG
沿 SVG 路径动画化元素。当需要沿路径移动对象时使用(例如曲线或自定义路线)。
gsap.registerPlugin(MotionPathPlugin);
gsap.to(".dot", {
duration: 2,
motionPath: { path: "#path", align: "#path", alignOrigin: [0.5, 0.5] }
});
MotionPath — 关键配置(motionPath 对象):
| 选项 | 描述 |
|---|---|
path | SVG 路径元素、选择器或路径数据字符串 |
align | 要将目标对齐到的路径元素或选择器 |
alignOrigin | [x, y] 原点(0–1);默认 [0.5, 0.5] |
autoRotate | 旋转元素以跟随路径切线 |
curviness | 0–2;路径平滑度 |
MotionPath 的可视化编辑器(对齐、偏移)。在开发期间用于调整路径对齐。
gsap.registerPlugin(MotionPathPlugin, MotionPathHelperPlugin);
const helper = MotionPathHelper.create(".dot", "#path", { end: 0.5 });
// 在 UI 中调整,然后在动画中使用 helper.path 或 helper.getProgress()
自定义缓动曲线(三次贝塞尔曲线或 SVG 路径)。当内置缓动不够时使用。基本用法在 gsap-core 中涵盖;使用时注册:
gsap.registerPlugin(CustomEase);
const ease = CustomEase.create("name", ".17,.67,.83,.67");
gsap.to(".el", { x: 100, ease: ease, duration: 1 });
添加更多命名的缓动(例如 SlowMo、RoughEase、ExpoScaleEase)。注册并在补间中使用缓动名称。
摆动/摇晃缓动。当值应该“摆动”时使用(多次振荡)。
具有可配置强度的弹跳式缓动。
2D 物理(速度、角度、重力)。当需要简单物理动画时使用(例如抛射物、弹跳)。
gsap.registerPlugin(Physics2DPlugin);
gsap.to(".ball", {
duration: 2,
physics2D: {
velocity: 250,
angle: 80,
gravity: 500
}
});
将物理应用于属性值。用于物理驱动的属性动画。
gsap.registerPlugin(PhysicsPropsPlugin);
gsap.to(".obj", {
duration: 2,
physicsProps: {
x: { velocity: 100, end: 300 },
y: { velocity: -50, acceleration: 200 }
}
});
用于擦洗时间线、切换动画和调试的 UI。仅在开发期间使用;不要发布。注册并使用时间线引用创建实例。
gsap.registerPlugin(GSDevTools);
GSDevTools.create({ animation: tl });
将 GSAP 与 PixiJS 集成,用于动画化 Pixi 显示对象。当使用 GSAP 动画化 Pixi 对象时注册。
gsap.registerPlugin(PixiPlugin);
const sprite = new PIXI.Sprite(texture);
gsap.to(sprite, { pixi: { x: 200, y: 100, scale: 1.5 }, duration: 1 });
SplitTextInstance.revert())。每周安装量
917
仓库
GitHub 星标数
1.5K
首次出现
4 天前
安全审计
安装于
codex909
opencode908
cursor908
kimi-cli907
gemini-cli907
github-copilot907
Apply when using or reviewing code that uses GSAP plugins: registering plugins, scroll-to, flip/FLIP animations, draggable elements, SVG (DrawSVG, MorphSVG, MotionPath), text (SplitText, ScrambleText), physics, easing plugins (CustomEase, EasePack, CustomWiggle, CustomBounce), or GSDevTools. ScrollTrigger has its own skill (gsap-scrolltrigger).
Related skills: For core tweens use gsap-core ; for ScrollTrigger use gsap-scrolltrigger ; for React use gsap-react.
Register each plugin once so GSAP (and bundlers) know to include it. Use gsap.registerPlugin() with every plugin used in the project:
import gsap from "gsap";
import { ScrollToPlugin } from "gsap/ScrollToPlugin";
import { Flip } from "gsap/Flip";
import { Draggable } from "gsap/Draggable";
gsap.registerPlugin(ScrollToPlugin, Flip, Draggable);
Animates scroll position (window or a scrollable element). Use for “scroll to element” or “scroll to position” without ScrollTrigger.
gsap.registerPlugin(ScrollToPlugin);
gsap.to(window, { duration: 1, scrollTo: { y: 500 } });
gsap.to(window, { duration: 1, scrollTo: { y: "#section", offsetY: 50 } });
gsap.to(scrollContainer, { duration: 1, scrollTo: { x: "max" } });
ScrollToPlugin — key config (scrollTo object):
| Option | Description |
|---|---|
x, y | Target scroll position (number), or "max" for maximum |
element | Selector or element to scroll to (for scroll-into-view) |
offsetX, offsetY | Offset in pixels from the target position |
Smooth scroll wrapper (smooths native scroll). Requires ScrollTrigger and a specific DOM structure (content wrapper + smooth wrapper). Use when smooth, momentum-style scroll is needed. See GSAP docs for setup; register after ScrollTrigger. DOM structure would look like:
<body>
<div id="smooth-wrapper">
<div id="smooth-content">
<!--- ALL YOUR CONTENT HERE --->
</div>
</div>
<!-- position: fixed elements can go outside --->
</body>
Capture state with Flip.getState(), then apply changes (e.g. layout or class changes), then use Flip.from() to animate from the previous state to the new state (FLIP: First, Last, Invert, Play). Use when animating between two layout states (lists, grids, expanded/collapsed).
gsap.registerPlugin(Flip);
const state = Flip.getState(".item");
// change DOM (reorder, add/remove, change classes)
Flip.from(state, { duration: 0.5, ease: "power2.inOut" });
Flip — key config (Flip.from vars):
| Option | Description |
|---|---|
absolute | Use position: absolute during the flip (default: false) |
nested | When true, only the first level of children is measured (better for nested transforms) |
scale | When true, scale elements to fit (avoids stretch); default true |
simple | When true, only position/scale are animated (faster, less accurate) |
https://gsap.com/docs/v3/Plugins/Flip
Makes elements draggable, spinnable, or throwable with mouse/touch. Use for sliders, cards, reorderable lists, or any drag interaction.
gsap.registerPlugin(Draggable, InertiaPlugin);
Draggable.create(".box", { type: "x,y", bounds: "#container", inertia: true });
Draggable.create(".knob", { type: "rotation" });
Draggable — key config options:
| Option | Description |
|---|---|
type | "x", "y", "x,y", "rotation", "scroll" |
bounds | Element, selector, or { minX, maxX, minY, maxY } to constrain drag |
inertia |
Works with Draggable for momentum after release, or track the inertia/velocity of any property of any object so that it can then seamlessly glide to a stop using a simple tween. Register with Draggable when using inertia: true:
gsap.registerPlugin(Draggable, InertiaPlugin);
Draggable.create(".box", { type: "x,y", inertia: true });
Or track velocity of a property:
InertiaPlugin.track(".box", "x");
Then use "auto" to continue the current velocity and glide to a stop:
gsap.to(obj, { inertia: { x: "auto" } });
Normalizes pointer and scroll input across devices. Use for swipe, scroll direction, or custom gesture logic without tying directly to scroll position like ScrollTrigger.
gsap.registerPlugin(Observer);
Observer.create({
target: "#area",
onUp: () => {},
onDown: () => {},
onLeft: () => {},
onRight: () => {},
tolerance: 10
});
Observer — key config options:
| Option | Description |
|---|---|
target | Element or selector to observe |
onUp, onDown, onLeft, onRight | Callbacks when swipe/scroll passes tolerance in that direction |
tolerance | Pixels before direction is detected; default 10 |
type | "touch", , or (default: ) |
Splits an element’s text into characters, words, and/or lines (each in its own element) for staggered or per-unit animation. Use when animating text character-by-character, word-by-word, or line-by-line. Returns an instance with chars , words , lines (and masks when mask is set). Restore original markup with revert() or let gsap.context() revert. Integrates with gsap.context() , matchMedia() , and useGSAP(). API: SplitText.create(target, vars) (target = selector, element, or array).
gsap.registerPlugin(SplitText);
const split = SplitText.create(".heading", { type: "words, chars" });
gsap.from(split.chars, { opacity: 0, y: 20, stagger: 0.03, duration: 0.4 });
// later: split.revert() or let gsap.context() cleanup revert
With onSplit() (v3.13.0+), animations run on each split and on re-split when autoSplit is used; returning a tween/timeline from onSplit() lets SplitText clean up and sync progress on re-split:
SplitText.create(".split", {
type: "lines",
autoSplit: true,
onSplit(self) {
return gsap.from(self.lines, { y: 100, opacity: 0, stagger: 0.05, duration: 0.5 });
}
});
SplitText — key config (SplitText.create vars):
| Option | Description |
|---|---|
| type | Comma-separated: "chars", "words", "lines". Default "chars,words,lines". Only split what is needed (e.g. "words, chars" if not using lines) for performance. Avoid chars-only without words/lines or use smartWrap: true to prevent odd line breaks. |
| charsClass , wordsClass , linesClass | CSS class on each split element. Append "++" to add an incremented class (e.g. linesClass: "line++" → , , …). |
Tips: Split only what is animated (e.g. skip chars if only animating words). For custom fonts, split after they load (e.g. document.fonts.ready.then(...)) or use autoSplit: true with onSplit(). To avoid kerning shift when splitting chars, use CSS font-kerning: none; text-rendering: optimizeSpeed;. Avoid text-wrap: balance; it can interfere with splitting. SplitText does not support SVG <text>.
Learn more: SplitText
Animates text with a scramble/glitch effect. Use when revealing or transitioning text with a scramble.
gsap.registerPlugin(ScrambleTextPlugin);
gsap.to(".text", {
duration: 1,
scrambleText: { text: "New message", chars: "01", revealDelay: 0.5 }
});
Reveals or hides the stroke of SVG elements by animating stroke-dashoffset / stroke-dasharray. Works on <path>, <line>, <polyline>, <polygon>, <rect>, <ellipse>. Use when “drawing” or “erasing” strokes.
drawSVG value: Describes the visible segment of the stroke along the path (start and end positions), not “animate from A to B over time.” Format: "start end" in percent or length. Examples: "0% 100%" = full stroke; "20% 80%" = stroke only between 20% and 80% (gaps at both ends). The tween animates from the element’s current segment to the target segment — e.g. gsap.to("#path", { drawSVG: "0% 100%" }) goes from whatever it is now to full stroke. Single value (e.g. 0, "100%") means start is 0: "100%" is equivalent to "0% 100%".
Required: The element must have a visible stroke — set stroke and stroke-width in CSS or as SVG attributes; otherwise nothing is drawn.
gsap.registerPlugin(DrawSVGPlugin);
// draw from nothing to full stroke
gsap.from("#path", { duration: 1, drawSVG: 0 });
// or explicit segment: from 0–0 to 0–100%
gsap.fromTo("#path", { drawSVG: "0% 0%" }, { drawSVG: "0% 100%", duration: 1 });
// stroke only in the middle (gaps at ends)
gsap.to("#path", { duration: 1, drawSVG: "20% 80%" });
Caveats: Only affects stroke (not fill). Prefer single-segment <path> elements; multi-segment paths can render oddly in some browsers. Contents of <use> cannot be visually changed. DrawSVGPlugin.getLength(element) and DrawSVGPlugin.getPosition(element) return stroke length and current position.
Learn more: DrawSVG
Morphs one SVG shape into another by animating the d attribute (path data). Start and end shapes do not need the same number of points — MorphSVG converts to cubic beziers and adds points as needed. Use for icon-to-icon morphs, shape transitions, or path-based animations. Works on <path>, <polyline>, and <polygon>; <circle>, <rect>, <ellipse>, and <line> are converted internally or via MorphSVGPlugin.convertToPath(selector | element) (replaces the element in the DOM with a <path>).
morphSVG value: Can be a selector (e.g. "#lightning"), an element , raw path data (e.g. "M47.1,0.8 73.3,0.8..."), or for polygon/polyline a points string (e.g. "240,220 240,70 70,70 70,220"). For full config use the object form with shape as the only required property.
gsap.registerPlugin(MorphSVGPlugin);
// convert primitives to path first if needed:
MorphSVGPlugin.convertToPath("circle, rect, ellipse, line");
gsap.to("#diamond", { duration: 1, morphSVG: "#lightning", ease: "power2.inOut" });
// object form:
gsap.to("#diamond", {
duration: 1,
morphSVG: { shape: "#lightning", type: "rotational", shapeIndex: 2 }
});
MorphSVG — key config (morphSVG object):
| Option | Description |
|---|---|
| shape | (Required.) Target shape: selector, element, or raw path string. |
| type | "linear" (default) or "rotational". Rotational uses angle/length interpolation and can avoid kinks mid-morph; try it when linear looks wrong. |
| map | How segments are matched: "size" (default), "position", or "complexity". Use when start/end segments don’t line up; if none work, split into multiple paths and morph each. |
| shapeIndex | Offsets which point in the start path maps to the first point in the end path (avoids shape “crossing over” or inverting). Number for single-segment paths; for multi-segment (e.g. ). Negative reverses that segment. Use once to log the auto-calculated value, then paste the number/array into the tween. (separate utility) provides an interactive UI to find a good value. Only applies to closed paths. |
Utilities: MorphSVGPlugin.convertToPath(selector | element) converts circle/rect/ellipse/line/polygon/polyline to <path> in the DOM. MorphSVGPlugin.rawPathToString(rawPath) and stringToRawPath(d) convert between path strings and raw arrays. The plugin stores the original d on the target (e.g. for tweening back: morphSVG: "#originalId" or the same element).
Tips: For twisted or inverted morphs, set shapeIndex (use "log" or findShapeIndex()). For multi-segment paths, shapeIndex is an array (one value per segment). Precompile only when the first frame is slow; it does not fix jank during the tween (simplify the SVG or reduce size if needed).
Learn more: MorphSVG
Animates an element along an SVG path. Use when moving an object along a path (e.g. a curve or custom route).
gsap.registerPlugin(MotionPathPlugin);
gsap.to(".dot", {
duration: 2,
motionPath: { path: "#path", align: "#path", alignOrigin: [0.5, 0.5] }
});
MotionPath — key config (motionPath object):
| Option | Description |
|---|---|
path | SVG path element, selector, or path data string |
align | Path element or selector to align the target to |
alignOrigin | [x, y] origin (0–1); default [0.5, 0.5] |
autoRotate | Rotate element to follow path tangent |
curviness |
Visual editor for MotionPath (alignment, offset). Use during development to tune path alignment.
gsap.registerPlugin(MotionPathPlugin, MotionPathHelperPlugin);
const helper = MotionPathHelper.create(".dot", "#path", { end: 0.5 });
// adjust in UI, then use helper.path or helper.getProgress() in your animation
Custom easing curves (cubic-bezier or SVG path). Use when a built-in ease is not enough. Basic usage is covered in gsap-core; register when using:
gsap.registerPlugin(CustomEase);
const ease = CustomEase.create("name", ".17,.67,.83,.67");
gsap.to(".el", { x: 100, ease: ease, duration: 1 });
Adds more named eases (e.g. SlowMo, RoughEase, ExpoScaleEase). Register and use the ease names in tweens.
Wiggle/shake easing. Use when a value should “wiggle” (multiple oscillations).
Bounce-style easing with configurable strength.
2D physics (velocity, angle, gravity). Use when animating with simple physics (e.g. projectiles, bouncing).
gsap.registerPlugin(Physics2DPlugin);
gsap.to(".ball", {
duration: 2,
physics2D: {
velocity: 250,
angle: 80,
gravity: 500
}
});
Applies physics to property values. Use for physics-driven property animation.
gsap.registerPlugin(PhysicsPropsPlugin);
gsap.to(".obj", {
duration: 2,
physicsProps: {
x: { velocity: 100, end: 300 },
y: { velocity: -50, acceleration: 200 }
}
});
UI for scrubbing timelines, toggling animations, and debugging. Use during development only; do not ship. Register and create an instance with a timeline reference.
gsap.registerPlugin(GSDevTools);
GSDevTools.create({ animation: tl });
Integrates GSAP with PixiJS for animating Pixi display objects. Register when animating Pixi objects with GSAP.
gsap.registerPlugin(PixiPlugin);
const sprite = new PIXI.Sprite(texture);
gsap.to(sprite, { pixi: { x: 200, y: 100, scale: 1.5 }, duration: 1 });
SplitTextInstance.revert()) when components unmount or elements are removed.https://gsap.com/docs/v3/Plugins/
Weekly Installs
917
Repository
GitHub Stars
1.5K
First Seen
4 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex909
opencode908
cursor908
kimi-cli907
gemini-cli907
github-copilot907
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
duration, ease | Standard tween options |
true to enable throw/momentum (requires InertiaPlugin) |
edgeResistance | 0–1; resistance when dragging past bounds |
cursor | CSS cursor during drag |
onDragStart, onDrag, onDragEnd | Callbacks; receive event and target |
onThrowUpdate, onThrowComplete | Callbacks when inertia is active |
"pointer""wheel""touch,pointer"line1line2| aria | "auto" (default), "hidden", or "none". Accessibility: "auto" adds aria-label on the split element and aria-hidden on line/word/char elements so screen readers read the label; "hidden" hides all from readers; "none" leaves aria unchanged. Use "none" plus a screen-reader-only duplicate if nested links/semantics must be exposed. |
| autoSplit | When true, reverts and re-splits when fonts finish loading or when the element width changes (and lines are split), avoiding wrong line breaks. Animations must be created inside onSplit() so they target the newly split elements; return the animation from onSplit() for automatic cleanup and time-sync on re-split. |
| onSplit(self) | Callback when split completes (and on each re-split if autoSplit is true). Receives the SplitText instance. Returning a GSAP tween or timeline enables automatic revert/sync of that animation when re-splitting. |
| mask | "lines", "words", or "chars". Wraps each unit in an extra element with overflow: clip for mask/reveal effects. Only one type; access wrappers on the instance’s masks array (or use class -mask if a class is set). |
| tag | Wrapper element tag; default "div". Use "span" for inline (note: transforms like rotation/scale may not render on inline elements in some browsers). |
| deepSlice | When true (default), nested elements (e.g. <strong>) that span multiple lines are subdivided so lines don’t stretch vertically. Only applies when splitting lines. |
| ignore | Selector or element(s) to leave unsplit (e.g. ignore: "sup"). |
| smartWrap | When splitting chars only, wraps words in a white-space: nowrap span to avoid mid-word line breaks. Ignored if words or lines are split. Default false. |
| wordDelimiter | Word boundary: string (default " "), RegExp, or { delimiter: RegExp, replaceWith: string } for custom splitting (e.g. zero-width joiner for hashtags, or non-Latin). |
| prepareText(text, parent) | Function that receives raw text and parent element; return modified text before splitting (e.g. to insert break markers for languages without spaces). |
| propIndex | When true, adds a CSS variable with index on each split element (e.g. --word: 1, --char: 2). |
| reduceWhiteSpace | Collapse consecutive spaces; default true. From v3.13.0 also honors line breaks and can insert <br> for <pre>. |
| onRevert | Callback when the instance is reverted. |
[5, 1, -8]| smooth | (v3.14+). Adds smoothing points. Number (e.g. 80), "auto", or object: `{ points: 40 |
| curveMode | Boolean (v3.14+). Interpolates control-handle angle/length instead of raw x/y to avoid kinks on curves. Try if a morph has a mid-morph kink. |
| origin | Rotation origin for type: "rotational". String: "50% 50%" (default) or "20% 60%, 35% 90%" for different start/end origins. |
| precision | Decimal places for output path data; default 2. |
| precompile | Array of precomputed path strings (or use precompile: "log" once, copy from console). Skips expensive startup calculations; use for very complex morphs. Only for <path> (convert polygon/polyline first). |
| render | Function(rawPath, target) called each update — e.g. draw to canvas. RawPath is an array of segments (each segment = array of alternating x,y cubic bezier coords). |
| updateTarget | When using render (e.g. canvas-only), set updateTarget: false so the original <path> is not updated. MorphSVGPlugin.defaultUpdateTarget sets default. |
| 0–2; path smoothing |