Communitygithub.com

Kiddo4993/Claude-Skills

實現捲動驅動的動畫 — 視差效果、滾動顯現、進度指示器、固定標題以及用於代理商和產品網站的 GSAP ScrollTrigger 序列。

Claude-Skills 是什麼?

此技能專注於為高端代理商和產品級網站,實現流暢且具電影感的捲動驅動動畫。它支援兩種主流前端動畫工具:Framer Motion 適用於 React 元件和單一元素(如淡入淡出、滑入、視差效果),而 GSAP ScrollTrigger 則擅長處理複雜的時間軸、固定序列和拖拽式效果(如水平滾動和文字逐行顯示)。技能內容提供可直接複製的 TypeScript/JSX 程式碼範例,包含效能最佳化規則(僅動畫化 transform 和 opacity、使用 will-change、清理 ScrollTrigger 實例)以及避免動畫過早觸發的技巧,幫助開發者避免常見的效能陷阱,打造高品質的捲動互動體驗。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Kiddo4993/Claude-Skills/tree/HEAD/scroll-animations

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

預覽

來自技能 README

Claude-Skills preview

說明文件

捲動動畫技能 — 代理商 / 產品級品質

滾動動畫是高預算網站展現價值的關鍵。做得好的話,它們感覺像電影;做不好則會引起暈動症。這項技能會正確地實現它們。

兩種方法

使用案例工具
React 元件、單一元素Framer Motion useScroll + useTransform
複雜時間軸、固定序列、拖拽效果GSAP ScrollTrigger

Framer Motion:滾動進入時的淡入 + 滑入效果

import { motion, useInView } from 'framer-motion'
import { useRef } from 'react'

function RevealOnScroll({ children, delay = 0 }: { children: React.ReactNode; delay?: number }) {
  const ref = useRef(null)
  const isInView = useInView(ref, { once: true, margin: '-80px 0px' })

  return (
    <motion.div
      ref={ref}
      initial={{ opacity: 0, y: 32, filter: 'blur(6px)' }}
      animate={isInView ? { opacity: 1, y: 0, filter: 'blur(0px)' } : {}}
      transition={{ type: 'spring', stiffness: 200, damping: 24, delay }}
    >
      {children}
    </motion.div>
  )
}

Framer Motion:滾動進度條

import { useScroll, useSpring, motion } from 'framer-motion'

function ScrollProgressBar() {
  const { scrollYProgress } = useScroll()
  const scaleX = useSpring(scrollYProgress, { stiffness: 100, damping: 30 })

  return (
    <motion.div
      className="fixed top-0 left-0 right-0 h-[3px] bg-blue-500 origin-left z-50"
      style={{ scaleX }}
    />
  )
}

Framer Motion:視差英雄圖片

import { useScroll, useTransform, motion } from 'framer-motion'
import { useRef } from 'react'

function ParallaxHero() {
  const ref = useRef(null)
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start start', 'end start'] })
  const y = useTransform(scrollYProgress, [0, 1], ['0%', '30%'])
  const opacity = useTransform(scrollYProgress, [0, 0.6], [1, 0])

  return (
    <section ref={ref} className="relative h-screen overflow-hidden">
      <motion.div className="absolute inset-0" style={{ y }}>
        <img src="/hero.jpg" className="w-full h-full object-cover" alt="" />
      </motion.div>
      <motion.div className="relative z-10 flex items-center justify-center h-full" style={{ opacity }}>
        <h1 className="text-white text-7xl font-bold">英雄文字</h1>
      </motion.div>
    </section>
  )
}

GSAP ScrollTrigger:固定式水平滾動(Awwwards 風格)

import { useEffect, useRef } from 'react'
import { gsap } from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'

gsap.registerPlugin(ScrollTrigger)

function HorizontalScrollSection() {
  const sectionRef = useRef(null)
  const trackRef = useRef(null)

  useEffect(() => {
    const track = trackRef.current
    const totalWidth = track.scrollWidth - window.innerWidth

    gsap.to(track, {
      x: -totalWidth,
      ease: 'none',
      scrollTrigger: {
        trigger: sectionRef.current,
        start: 'top top',
        end: `+=${totalWidth}`,
        scrub: 1,
        pin: true,
        anticipatePin: 1,
      }
    })

    return () => ScrollTrigger.getAll().forEach(t => t.kill())
  }, [])

  return (
    <section ref={sectionRef} className="overflow-hidden">
      <div ref={trackRef} className="flex w-max gap-8 p-16">
        {panels.map((panel, i) => (
          <div key={i} className="w-[80vw] h-screen flex-shrink-0 bg-gray-100 rounded-2xl" />
        ))}
      </div>
    </section>
  )
}

GSAP ScrollTrigger:交錯文字顯現(逐行)

useEffect(() => {
  const lines = gsap.utils.toArray('.reveal-line')

  lines.forEach((line, i) => {
    gsap.fromTo(line,
      { y: '100%', opacity: 0 },
      {
        y: '0%',
        opacity: 1,
        duration: 0.8,
        ease: 'power3.out',
        delay: i * 0.1,
        scrollTrigger: {
          trigger: line,
          start: 'top 90%',
          toggleActions: 'play none none none'
        }
      }
    )
  })

  return () => ScrollTrigger.getAll().forEach(t => t.kill())
}, [])

滾動動畫的效能規則

  • 只對 transform 和 opacity 進行動畫 — 絕對不要使用 top、left、width、height
  • 對持續進行滾動動畫的元素添加 will-change: transform
  • 始終在 useEffect 的返回中清理 ScrollTrigger 實例
  • 使用 scrub: 1(而不是 scrub: true)來實現平滑拖拽
  • 在低階 Android 裝置上測試 — 如果在那裡掉幀,表示它出貨時就有問題
  • useInView 中的 margin: '-80px 0px' 可防止動畫過早觸發

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

相關技能