Scroll driven web experience

From findscripter/everything-skills · View interactive version

Scroll driven web experience is an AI agent skill from the GitHub repository findscripter/everything-skills. 当需要把网页做成「随滚动展开的叙事/电影感」体验(视差、滚动动画、Pin 钉住、横向滚动、进度揭示)时使用;产出滚动驱动的页面方案与可运行代码(GSAP ScrollTrigger / Framer Motion / CSS scroll-timeline),含 60fps 性能、移动端与无障碍兜底;不适用于普通静态页排版、纯 3D/WebGL(转 3d-web-experience)、框架级实现(转 frontend);触发词:滚动动画、视差、滚动叙事

How to use this skill

Skill file

何时使用

当你要把页面从「能读」升级为「随手指滚动展开的电影/叙事体验」时使用,典型场景:视差讲故事、滚动触发的揭示与进度条、Pin 钉住区块、横向滚动面板、产品功能逐帧走查、Before/After 对比。把滚动当成叙事装置而非单纯导航。

不该用的边界:

步骤 / 指令

  1. 先定叙事节拍(story beats),再写动画。推荐五段式:钩子(满屏视觉)→ 背景铺垫 → 旅程(视差)→ 高潮(戏剧化揭示)→ 收尾(CTA/结论)。
  2. 选库:复杂动画用 GSAP ScrollTrigger(学习曲线中);React 项目用 Framer Motion(低);只要平滑滚动用 Lenis(低);平滑滚动+视差用 Locomotive Scroll(中);简单原生场景用 CSS scroll-timeline(低)。
  3. 内容优先(Progressive Enhancement):先保证无 JS 时内容可读、首屏即见核心信息与 CTA;动画只做增强。文本进 DOM 而非 canvas,保留标题层级与 SEO。
  4. 实现动画:只动 transform 和 opacity,目标 60fps。
  5. 移动端降级:检测后减少视差强度/图层数,低端可禁用。
  6. 无障碍兜底:尊重 prefers-reduced-motion,不要劫持滚动(用 scrub 跟随而非 hijack),保留键盘可达与跳转链接。
  7. 用 GSAP markers: true 与 Chrome DevTools Performance 面板调试,录制滚动找红帧、开 Paint flashing,并在真机/限频 CPU 上验证。

示例

GSAP ScrollTrigger 基础(scrub 把动画绑定到滚动位置):

import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);

gsap.to('.element', {
  scrollTrigger: { trigger: '.element', start: 'top center', end: 'bottom center', scrub: true },
  y: -100, opacity: 1,
});

视差分层(背景慢、前景快,制造景深):背景 0.2x、中景 0.5x、前景/正文 1.0x、漂浮元素 1.2x。

gsap.to('.background', { scrollTrigger: { scrub: true }, y: '-20%' }); // 慢
gsap.to('.foreground', { scrollTrigger: { scrub: true }, y: '-50%' }); // 快

Pin 钉住 + 横向滚动面板:

const sections = gsap.utils.toArray('.panel');
gsap.to(sections, {
  xPercent: -100 * (sections.length - 1), ease: 'none',
  scrollTrigger: {
    trigger: '.horizontal-container', pin: true, scrub: 1,
    end: () => '+=' + document.querySelector('.horizontal-container').offsetWidth,
  },
});

Framer Motion 滚动视差:

import { motion, useScroll, useTransform } from 'framer-motion';
function ParallaxSection() {
  const { scrollYProgress } = useScroll();
  const y = useTransform(scrollYProgress, [0, 1], [0, -200]);
  return <motion.div style={{ y }}>Content moves with scroll</motion.div>;
}

CSS 原生(无 JS、移动端更稳):

.animate-on-scroll {
  animation: reveal linear;
  animation-timeline: view();
  animation-range: entry 0% cover 40%;
}
@supports (animation-timeline: scroll()) {
  .parallax { animation: parallax linear; animation-timeline: scroll(); }
}

CSS Sticky 钉住(容器留出滚动空间):

.sticky-container { height: 300vh; }
.sticky-element { position: sticky; top: 0; height: 100vh; }

注意事项

let ticking = false;
window.addEventListener('scroll', () => {
  if (!ticking) { requestAnimationFrame(() => { heavyFunction(); ticking = false; }); ticking = true; }
});
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

JS 侧用 window.matchMedia('(prefers-reduced-motion: reduce)').matches 决定是否初始化动画。

互见


采编自 sickn33/antigravity-awesome-skills(源条目 scroll-experience,上游 vibeship-spawner-skills,Apache 2.0;MIT)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.