Jump to content
GreenSock

Kushal

gsap."from" is not working when used with scrolltrigger

Recommended Posts

import "./component.scss";
 
import CSSRulePlugin from "gsap/CSSRulePlugin";
import ScrollTrigger from "gsap/src/ScrollTrigger";
import gsap from "gsap";
import { useEffect, useRef } from "react";


 
const Heading = (props) =>{
    let headingContainer = useRef(null);
    gsap.registerPlugin(CSSRulePlugin,ScrollTrigger);
 
    useEffect(()=>{
        gsap.from(
            headingContainer,
            {scrollTrigger:{trigger:headingContainer,start:"top center",toggleActions:"restart none none none"}, duration:1,
            autoAlpha:1,
            y:0,
            ease:"power1.easeOut"
           
        }
        );
    },[])
    return(
        <>
        <div className="heading-container" ref={el=>{headingContainer=el}}>
            <div className="heading-content">
                <h2>{props.content}</h2>
            </div>
            <div className="heading-diamond"></div>
        </div>
        </>
    )
}
 
export default Heading
Link to comment
Share on other sites

When I try to use it, as soon as the it is triggered it goes from x:50 i.e translate(50px,0px) to translate3d(0,50px,0), also autoAlpha:0 doesn't get triggered. I am using react.

Link to comment
Share on other sites

Also, Its going back to its initial x:50

Link to comment
Share on other sites

Without a minimal demo very hard to say whats wrong 

If you want create demo with React you can use codesandbox

The presented code is not enough to understand what the problem is

  • Like 2
Link to comment
Share on other sites

If you're having trouble, please make a minimal demo. Thanks!

 

  • Like 1
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.
×