Jump to content
Search Community

i use scrolltrigger in react and the simple runnig well but when i try to make with scrolltrigger it not do anything and it add an unknown maker to my window on top

kanishk soni test
Moderator Tag

Go to solution Solved by kanishk soni,

Recommended Posts

import React, { useEffect, useRef, useState } from "react";
import { motion } from "framer-motion";
import mypic from "../public/images/Untitled-transformed.jpeg";
import video from "../public/Videos/workportfilio.mp4";
import { useGSAP } from "@gsap/react";
import gsap from "gsap";
import { ScrollTrigger } from 'gsap/ScrollTrigger';

const Home = () => {

 const aboutsectiontextanimtion = useRef();
 const parentofaboutsectiontextanimtion = useRef()
  useEffect(() => {
    if (aboutsectiontextanimtion.current && parentofaboutsectiontextanimtion.current) {
      gsap.to(aboutsectiontextanimtion.current, {
        x: '30vw',
        scrollTrigger: {
          trigger: aboutsectiontextanimtion.current,
          scroller: parentofaboutsectiontextanimtion.current,
          scrub: 1,
          start: "top middle",
          end: "+=90",
          markers: true,
          pin: true,
  }, []);

 return (
 <div ref={parentofaboutsectiontextanimtion} className="bg-blue-500 h-[140vh] rounded-lg w-full">
                <div ref={aboutsectiontextanimtion} className="text-7xl">acavasvasv</div>



i reinstall all require node pacakges but it still not owrking

Link to comment
Share on other sites

Hi there! I see you're using React -

Proper cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE.


Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down.


Here is how it works:

const container = useRef(); // the root level element of your component (for scoping selector text which is optional)

useGSAP(() => {
  // gsap code here...
}, { dependencies: [endX], scope: container }); // config object offers maximum flexibility

Or if you prefer, you can use the same method signature as useEffect():

useGSAP(() => {
  // gsap code here...
}, [endX]); // simple dependency Array setup like useEffect()

This pattern follows React's best practices.


We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/


If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...