GSAP 3D Effect in Reactjs

GSAP 3D Effect in Reactjs




Here some Basic step to follow while create animation in GSAP.

1 : Register scrollTrigger plugin. while trigger element on scroll.
2 : Create React Hooks and write gsap code inside it.
3 : Use gsap.context(), 
Collects all GSAP animations and ScrollTrigger that are created within the supplied function so that you can easily revert() or kill()ALL of them at once.
4 : Create timeline and scrollTrigger base on your requirements.

3D animation using GSAP and reactjs.

Create reactjs project and install gsap using npm install gsap command.

HTML

GSAP 3D effect animation with use of reactjs



CSS 


body {
    background-color#202020;
    colorwhite;
    font-size18px;
    overflow-xhidden;
}

h1 {
    font-family'Playfair Display'serif;
    font-size96px;
}

.wrapper {
    displayflex;
    align-itemscenter;
    justify-contentcenter;
    width100%;
    height100%;
    padding5vh 5%;
}

.panel {
    positionrelative;
    displayflex;
    width100%;
    max-width1200px;
    height466px;
    user-selectnone;
    pointer-eventsnone;   
}

.panelBlock {
    flex-basis25%;
}

.content {
    positionabsolute;
    top26%;
    left0;
    z-index2;
    width100%;
}

.text {
    displayinline-block;
    text-alignright;
}

.imgCol {
    width100%;
}

.imgContent {
    displayblock;
    width100%;
    height100%;
    object-fitcover;
}

.imgCol {
    flex-basis70%;
    box-shadow0px 20px 100.28px 8.72px rgba(0000.35);
}


.title {
    margin0;
}



Use GSAP Method to create loader animation. Different Method of GSAP you can check below link
https://www.codeforinfo.com/2023/06/useful-gsap-method-to-create-gsap.html

GSAP animation

create useRef() to access DOM elements.


let panelContent = useRef(null);
let panelImgCol = useRef(null);




useEffect(() => {

        let ctx = gsap.context(() => {

            var body = document.getElementsByTagName("body");
            initTilt();
            function initTilt() {
                console.log("Call init");
                TweenMax.set([panelContentpanelImgCol], 
                transformStyle: "preserve-3d" });

                body[0].addEventListener("mousemove", (e=> {
                    animi(e.pageXe.pageY)
                });
            };

            function animi(cxcy) {
                console.log("x,y"cxcy);
                var sxPos = (cx / window.innerWidth * 100 - 50) * 2;
                var syPos = (cy / window.innerHeight * 100 - 50) * 2;

                console.log("sx,sx"sxPossyPos);
                TweenMax.to(panelContent2, {
                    rotationY: -0.03 * sxPos,
                    rotationX: 0.03 * syPos,
                    transformPerspective: 500,
                    transformOrigin: "center center -400",
                    ease: Expo.easeOut
                });
                TweenMax.to(panelImgCol2, {
                    rotationY: -0.03 * sxPos,
                    rotationX: 0.03 * syPos,
                    transformPerspective: 500,
                    transformOrigin: "center center -200",
                    ease: Expo.easeOut
                });
            }

            body[0].addEventListener("mouseleave", () => {
                animi(window.innerWidth / 2window.innerHeight / 2);
            });

        });
        return () => ctx.revert();
    }, [])


Locomotive scroll landing page design

Previous Post Next Post