npx skills add https://github.com/greensock/gsap-skills --skill gsap-timeline当构建多步骤动画、按顺序或并行协调多个补间动画,或用户询问 GSAP 中的时间轴、序列或关键帧样式动画时应用。
相关技能: 对于单个补间动画和缓动效果,使用 gsap-core;对于滚动驱动的时间轴,使用 gsap-scrolltrigger;对于 React,使用 gsap-react。
const tl = gsap.timeline();
tl.to(".a", { x: 100, duration: 1 })
.to(".b", { y: 50, duration: 0.5 })
.to(".c", { opacity: 0, duration: 0.3 });
默认情况下,补间动画会依次追加。使用位置参数将补间动画放置在特定时间点或相对于其他补间动画的位置。
第三个参数(或 vars 对象中的 position 属性)控制放置位置:
1 — 在 1 秒时开始。"+=0.5" — 上一个动画结束后 0.5 秒;"-=0.2" — 上一个动画结束前 0.2 秒。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
"labelName""labelName+=0.3""<" — 与最近添加的动画同时开始;">" — 在最近添加的动画结束时开始(默认);"<0.2" — 在最近添加的动画开始后 0.2 秒开始。示例:
tl.to(".a", { x: 100 }, 0); // 在 0 秒
tl.to(".b", { y: 50 }, "+=0.5"); // 上一个结束后 0.5 秒
tl.to(".c", { opacity: 0 }, "<"); // 与前一个同时开始
tl.to(".d", { scale: 2 }, "<0.2"); // 前一个开始后 0.2 秒
将默认值传递给时间轴,以便所有子补间动画继承:
const tl = gsap.timeline({ defaults: { duration: 0.5, ease: "power2.out" } });
tl.to(".a", { x: 100 }).to(".b", { y: 50 }); // 两者都使用 0.5 秒和 power2.out 缓动
.play() 开始。添加和使用标签以实现可读、可维护的序列:
tl.addLabel("intro", 0);
tl.to(".a", { x: 100 }, "intro");
tl.addLabel("outro", "+=0.5");
tl.to(".b", { opacity: 0 }, "outro");
tl.play("outro"); // 从 "outro" 开始播放
tl.tweenFromTo("intro", "outro"); // 暂停时间轴并返回一个新的补间动画,该动画将时间轴的播放头从 intro 无缓动地动画到 outro。
时间轴可以包含其他时间轴。
const master = gsap.timeline();
const child = gsap.timeline();
child.to(".a", { x: 100 }).to(".b", { y: 50 });
master.add(child, 0);
master.to(".c", { opacity: 0 }, "+=0.2");
addLabel() 添加标签,以实现可读、可维护的序列。gsap.timeline() 和位置参数。defaults: { duration: 0.5, ease: "power2.out" })。每周安装量
909
代码仓库
GitHub 星标数
1.5K
首次出现
4 天前
安全审计
已安装于
codex902
cursor901
opencode901
kimi-cli900
gemini-cli900
github-copilot900
Apply when building multi-step animations, coordinating several tweens in sequence or parallel, or when the user asks about timelines, sequencing, or keyframe-style animation in GSAP.
Related skills: For single tweens and eases use gsap-core ; for scroll-driven timelines use gsap-scrolltrigger ; for React use gsap-react.
const tl = gsap.timeline();
tl.to(".a", { x: 100, duration: 1 })
.to(".b", { y: 50, duration: 0.5 })
.to(".c", { opacity: 0, duration: 0.3 });
By default, tweens are appended one after another. Use the position parameter to place tweens at specific times or relative to other tweens.
Third argument (or position property in vars) controls placement:
1 — start at 1 second."+=0.5" — 0.5s after end; "-=0.2" — 0.2s before end."labelName" — at that label; "labelName+=0.3" — 0.3s after label."<" — start when recently-added animation starts; ">" — start when recently-added animation ends (default); "<0.2" — 0.2s after recently-added animation start.Examples:
tl.to(".a", { x: 100 }, 0); // at 0
tl.to(".b", { y: 50 }, "+=0.5"); // 0.5s after last end
tl.to(".c", { opacity: 0 }, "<"); // same start as previous
tl.to(".d", { scale: 2 }, "<0.2"); // 0.2s after previous start
Pass defaults into the timeline so all child tweens inherit:
const tl = gsap.timeline({ defaults: { duration: 0.5, ease: "power2.out" } });
tl.to(".a", { x: 100 }).to(".b", { y: 50 }); // both use 0.5s and power2.out
.play() to start.Add and use labels for readable, maintainable sequencing:
tl.addLabel("intro", 0);
tl.to(".a", { x: 100 }, "intro");
tl.addLabel("outro", "+=0.5");
tl.to(".b", { opacity: 0 }, "outro");
tl.play("outro"); // start from "outro"
tl.tweenFromTo("intro", "outro"); // pauses the timeline and returns a new Tween that animates the timeline's playhead from intro to outro with no ease.
Timelines can contain other timelines.
const master = gsap.timeline();
const child = gsap.timeline();
child.to(".a", { x: 100 }).to(".b", { y: 50 });
master.add(child, 0);
master.to(".c", { opacity: 0 }, "+=0.2");
addLabel() for readable, maintainable sequencing.gsap.timeline() and the position parameter for multi-step animation.defaults: { duration: 0.5, ease: "power2.out" }) when many child tweens share the same duration or ease.Weekly Installs
909
Repository
GitHub Stars
1.5K
First Seen
4 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex902
cursor901
opencode901
kimi-cli900
gemini-cli900
github-copilot900
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装