gsap-framer-scroll-animation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGSAP & Framer Motion — Scroll Animations Skill
GSAP & Framer Motion — 滚动动画技能
Production-grade scroll animations with GitHub Copilot prompts, ready-to-use code recipes, and deep API references.
Design Companion: This skill provides the technical implementation for scroll-driven motion. For the creative philosophy, design principles, and premium aesthetics that should guide how and when to animate, always cross-reference the premium-frontend-ui skill. Together they form a complete approach: premium-frontend-ui decides the what and why; this skill delivers the how.
附带GitHub Copilot提示词、开箱即用的代码示例和详尽API参考的生产级滚动动画方案。
设计配套说明: 本技能提供滚动驱动动效的技术实现方案。 如需了解指导动画制作方式和适用时机的创意理念、设计原则与高端美学, 请始终搭配参考 premium-frontend-ui 技能。 二者结合可形成完整的实现方案:premium-frontend-ui 决定「做什么」和「为什么做」; 本技能提供「怎么做」的实现方法。
Quick Library Selector
快速库选择器
| Need | Use |
|---|---|
| Vanilla JS, Webflow, Vue | GSAP |
| Pinning, horizontal scroll, complex timelines | GSAP |
| React / Next.js, declarative style | Framer Motion |
| whileInView entrance animations | Framer Motion |
| Both in same Next.js app | See notes in references |
Read the relevant reference file for full recipes and Copilot prompts:
- GSAP → — ScrollTrigger API, all recipes, React integration
references/gsap.md - Framer Motion → — useScroll, useTransform, all recipes
references/framer.md
| 需求 | 选用库 |
|---|---|
| 原生JS、Webflow、Vue | GSAP |
| 固定定位、横向滚动、复杂时间线 | GSAP |
| React / Next.js、声明式写法 | Framer Motion |
| whileInView入场动画 | Framer Motion |
| 同一个Next.js应用中同时使用二者 | 查看参考文档中的说明 |
阅读对应的参考文件获取完整示例和Copilot提示词:
- GSAP → — ScrollTrigger API、所有示例、React集成
references/gsap.md - Framer Motion → — useScroll、useTransform、所有示例
references/framer.md
Setup (Always Do First)
前置配置(必须最先完成)
GSAP
GSAP
bash
npm install gsapjs
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger); // MUST call before any ScrollTrigger usagebash
npm install gsapjs
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger); // MUST call before any ScrollTrigger usageFramer Motion (Motion v12, 2025)
Framer Motion (Motion v12, 2025)
bash
npm install motion # new package name since mid-2025bash
npm install motion # new package name since mid-2025or: npm install framer-motion — still works, same API
or: npm install framer-motion — still works, same API
```js
import { motion, useScroll, useTransform, useSpring } from 'motion/react';
// legacy: import { motion } from 'framer-motion' — also valid```js
import { motion, useScroll, useTransform, useSpring } from 'motion/react';
// legacy: import { motion } from 'framer-motion' — also validWorkflow
使用流程
- Interpret the user's intent to identify if GSAP or Framer Motion is the best fit.
- Read the relevant reference document in for detailed APIs and patterns.
references/ - Suggest the required package installation if not already present.
- Implement the scaffold for the animation structure, adhering to the requested format (React components, hook requirements, or vanilla JS).
- Apply the correct tools (scrolling vs in-view elements) ensuring accessibility options are present and hooks don't cause infinite re-renders.
- 分析用户需求,判断GSAP或Framer Motion哪个更适配。
- 阅读目录下对应的参考文档,获取详细API和实现模式。
references/ - 如果项目中尚未安装依赖,提示安装所需包。
- 按照要求的格式(React组件、Hook要求或原生JS)实现动画结构的脚手架。
- 选用正确的工具(滚动触发vs视图内元素触发),确保包含无障碍选项,且Hook不会导致无限重渲染。
The 5 Most Common Scroll Patterns
5种最常用滚动模式
Quick reference — full recipes with Copilot prompts are in the reference files.
快速参考 — 完整示例及Copilot提示词详见参考文件。
1. Fade-in on enter (GSAP)
1. 进入时淡入(GSAP)
js
gsap.from('.card', {
opacity: 0, y: 50, stagger: 0.15, duration: 0.8,
scrollTrigger: { trigger: '.card', start: 'top 85%' }
});js
gsap.from('.card', {
opacity: 0, y: 50, stagger: 0.15, duration: 0.8,
scrollTrigger: { trigger: '.card', start: 'top 85%' }
});2. Fade-in on enter (Framer Motion)
2. 进入时淡入(Framer Motion)
jsx
<motion.div
initial={{ opacity: 0, y: 40 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: '-80px' }}
transition={{ duration: 0.6 }}
/>jsx
<motion.div
initial={{ opacity: 0, y: 40 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: '-80px' }}
transition={{ duration: 0.6 }}
/>3. Scrub / scroll-linked (GSAP)
3. Scrub/滚动绑定动效(GSAP)
js
gsap.to('.hero-img', {
scale: 1.3, opacity: 0, ease: 'none',
scrollTrigger: { trigger: '.hero', start: 'top top', end: 'bottom top', scrub: true }
});js
gsap.to('.hero-img', {
scale: 1.3, opacity: 0, ease: 'none',
scrollTrigger: { trigger: '.hero', start: 'top top', end: 'bottom top', scrub: true }
});4. Scroll-linked (Framer Motion)
4. 滚动绑定动效(Framer Motion)
jsx
const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
const y = useTransform(scrollYProgress, [0, 1], [0, -100]);
return <motion.div style={{ y }} />;jsx
const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
const y = useTransform(scrollYProgress, [0, 1], [0, -100]);
return <motion.div style={{ y }} />;5. Pinned timeline (GSAP)
5. 固定时间线(GSAP)
js
const tl = gsap.timeline({
scrollTrigger: { trigger: '.section', pin: true, scrub: 1, start: 'top top', end: '+=200%' }
});
tl.from('.title', { opacity: 0, y: 60 }).from('.img', { scale: 0.85 });js
const tl = gsap.timeline({
scrollTrigger: { trigger: '.section', pin: true, scrub: 1, start: 'top top', end: '+=200%' }
});
tl.from('.title', { opacity: 0, y: 60 }).from('.img', { scale: 0.85 });Critical Rules (Apply Always)
核心规则(始终遵守)
- GSAP: always call before using it
gsap.registerPlugin(ScrollTrigger) - GSAP scrub: always use — easing feels wrong when scrub is active
ease: 'none' - GSAP React: use from
useGSAP, never plain@gsap/react— it auto-cleans ScrollTriggersuseEffect - GSAP debug: add during development; remove before production
markers: true - Framer: output must go into
useTransformprop of astyleelement, not a plain divmotion.* - Framer Next.js: always add at top of any file using motion hooks
'use client' - Both: animate only and
transform— avoidopacity,width,heightbox-shadow - Accessibility: always check — see each reference file for patterns
prefers-reduced-motion - Premium polish: follow the premium-frontend-ui skill principles for motion timing, easing curves, and restraint — animation should enhance, never overwhelm
- GSAP:使用前必须调用
gsap.registerPlugin(ScrollTrigger) - GSAP scrub模式:始终使用— scrub激活时加缓动会导致效果违和
ease: 'none' - GSAP React:使用提供的
@gsap/react,不要直接用普通useGSAP— 它会自动清理ScrollTrigger实例useEffect - GSAP调试:开发阶段添加;生产发布前移除
markers: true - Framer:的输出必须传入
useTransform元素的motion.*属性,不能用在普通div上style - Framer Next.js:所有使用motion Hook的文件顶部必须添加
'use client' - 二者通用:仅对和
transform属性做动画 — 避免动效作用于opacity、width、heightbox-shadow - 无障碍:始终检查设置 — 实现模式参考各参考文件
prefers-reduced-motion - 高端效果打磨:遵循premium-frontend-ui技能的动效时序、缓动曲线和克制原则 — 动画应该起增强作用,绝不能喧宾夺主
Copilot Prompting Tips
Copilot提示词编写技巧
- Give Copilot the full selector, base image, and scroll range upfront — vague prompts produce vague code
- For GSAP, always specify: selector, start/end strings, whether you want scrub or toggleActions
- For Framer, always specify: which hook (useScroll vs whileInView), offset values, what to transform
- Paste the exact error message when asking — Copilot fixes are dramatically better with real errors
/fix - Use scope in Copilot Chat so it reads your existing component structure
@workspace
- 提前给Copilot提供完整的选择器、基础结构和滚动范围 — 模糊的提示词会产出模糊的代码
- 针对GSAP,始终明确说明:选择器、start/end字符串、是否需要scrub或toggleActions
- 针对Framer,始终明确说明:使用哪个Hook(useScroll还是whileInView)、偏移值、要变换的属性
- 调用时粘贴准确的错误信息 — 有真实错误时Copilot的修复效果会好很多
/fix - 在Copilot Chat中使用作用域,让它读取你现有的组件结构
@workspace
Reference Files
参考文件
| File | Contents |
|---|---|
| Full ScrollTrigger API reference, 10 recipes, React (useGSAP), Lenis, matchMedia, accessibility |
| Full useScroll / useTransform API, 8 recipes, variants, Motion v12 notes, Next.js tips |
| 文件 | 内容 |
|---|---|
| 完整ScrollTrigger API参考、10个示例、React(useGSAP)、Lenis、matchMedia、无障碍适配 |
| 完整useScroll / useTransform API、8个示例、variants、Motion v12说明、Next.js使用技巧 |
Related Skills
关联技能
| Skill | Relationship |
|---|---|
| premium-frontend-ui | Creative philosophy, design principles, and aesthetic guidelines — defines when and why to animate |
| 技能 | 关联关系 |
|---|---|
| premium-frontend-ui | 创意理念、设计原则和美学指南 — 定义动画的适用时机和设计原因 |