💭

【GSAP】GSAP Practice【#23 GSAP Nextjs UseGSAP】

2025/02/11に公開

【#23 GSAP Nextjs UseGSAP】

YouTube: https://youtu.be/pncikP-2Gio
https://youtu.be/pncikP-2Gio

今回はNextjsのアプリ内でGSAPを使用する方法について
解説していきます。

https://gsap.com/resources/React/

npm install @gsap/react
app/page.tsx
'use client'

import { useRef } from 'react'
import gsap from 'gsap'
import { useGSAP } from '@gsap/react'

gsap.registerPlugin(useGSAP)

export default function Home() {
  useGSAP(() => {
    gsap.to('.box', { x: 360 })
  })

  return (
    <main className="w-screen h-screen">
      <div className="size-full flex items-center justify-center bg-slate-300">
        <div className="box w-40 h-40 bg-red-700 flex flex-col items-center justify-center text-white font-bold cursor-pointer">
          <p>box1</p>
        </div>
      </div>
      <div className="size-full flex items-center justify-center bg-rose-300">
        <h2 className="text-3xl font-bold">Section2</h2>
      </div>
      <div className="size-full flex items-center justify-center bg-sky-300">
        <h2 className="text-3xl font-bold">Section3</h2>
      </div>
    </main>
  )
}

Discussion