Communitygithub.com

Kiddo4993/Claude-Skills — スクロールアニメーション

パララックス、スクロール連動表示、プログレスバー、スティッキーヘッダー、GSAP ScrollTriggerシーケンスなど、アーリー採用サイトやプロダクトサイトで使われるスクロール駆動アニメーションを実装します。

Claude-Skills — スクロールアニメーション とは?

このスキルは、高品質なウェブサイトに求められるスクロールアニメーション(パララックス、表示連動アニメーション、プログレスインジケーター、スティッキーヘッダー、GSAP ScrollTriggerによる複雑なタイムライン)を実装するための包括的なガイドです。Framer MotionとGSAPという2つの主要なフレームワークをサポートしており、シンプルな単一要素のアニメーションにはFramer MotionのuseScrollとuseTransformを、複雑なタイムラインやピン留めシーケンス、スクラブを必要とする高度なアニメーションにはGSAP ScrollTriggerを使用することを推奨しています。各手法に対して具体的なTypeScriptコード例が用意されており、パララックスヒーロー画像、スクロールプログレスバー、水平スクロールセクション、テキストのスタッガー表示など、実際のプロジェクトで頻繁に使われるパターンをカバーしています。また、パフォーマンスに関する重要なルール(transformとopacityのみをアニメーション対象とする、ScrollTriggerのクリーンアップ、will-changeの適切な使用など)も詳述されており、プロダクション品質のアニメーションを実現するための実践的な知識を提供します。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Kiddo4993/Claude-Skills/tree/HEAD/scroll-animations

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

プレビュー

スキル README より

Claude-Skills — スクロールアニメーション preview

ドキュメント

スクロールアニメーションスキル — エージェンシー/プロダクト品質

スクロールアニメーションは、高予算サイトがその予算に値する理由です。正しく実装すれば映画的に感じられ、間違えると乗り物酔いを引き起こします。このスキルはそれらを正しく実装します。

2つのアプローチ

ユースケースツール
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 の return で常に ScrollTrigger インスタンスをクリーンアップする
  • スムーズなスクラブには scrub: true ではなく scrub: 1 を使用する
  • ローエンドのAndroid端末でテストする — そこでフレーム落ちするなら、出荷時に壊れている
  • useInView の margin: '-80px 0px' はアニメーションが早すぎるタイミングで発動するのを防ぐ

Individual skills in this repo

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

関連スキル