GSAP Layout Animation With reactJs

GSAP Layout Animation With reactJs



Smooth animation using GSAP,ScrollTrigger and reactjs

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


HTML 

in HTML code we create on ref for access elements. 

import gsap from "gsap";
import { TweenLiteTweenMaxPower3Power4Power1 } from "gsap";
<div>
            <div className="load-container">
                <div className="load-screen bottom"
                    ref={(el=> (screen = el)}></div>
            </div>
            <div ref={(el=> (body2 = el)} className="Headd">
                <main style={zIndex: 11position: "relative" }}>
                    <div className="box-container" style={zIndex: 11 }}>
                        <div className="tile box-1"></div>
                        <div className="tile box-2"></div>
                        <div className="tile box-3"></div>
                    </div>
                </main>
                <div className="container"
                    style={zIndex: 11position: "relative" }}>
                    <div className="page box-1">
                    </div>
                    <div className="page box-2">
                    </div>
                    <div className="page box-3">
                    </div>
                </div>
            </div>
        </div>


CSS 

.box-container {
    positionabsolute;
    top275px;
    right0;
    z-index11;
    left0;
    text-aligncenter;
    user-selectnone;
}
  
.tile {
    width200px;
    height200px;
    margin4px;
    cursorpointer;  
    z-index11;
    displayinline-block;
}
  
.container {
    visibilityhidden;
}
  
.page {
    cursorpointer;
    positionabsolute;
    height100vh;
    width100vw;
    top0;
    left0;
    positionfixed;
}
.imgClass{
      width0%;
      opacity0;
      height:100%;
      left:0;
}
.box-1 {
    background#F4DB33;
}
  
.box-2 {
    background#972FF8;
}
  
.box-3 {
    background#7DD6FE;
}


GSAP Animation

On first load call addListeners() Method for each box click.

GSAP Layout animation in reactjs



Inside addListeners() Method addEventListener() to tile and page click.

GSAP website animation



After onClick() of tile and page call animateBox() function to set style and position of page and boxes.

GSAP layout animation for website


 

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

let screen = useRef(null);
    let body2 = useRef(null);
    useEffect(() => {
        var tl = gsap.timeline();
        var root = document.documentElement;
        var body = document.body;
        var pages = document.querySelectorAll(".page");
        var tiles = document.querySelectorAll(".tile");
        tl.to(screen, {
            duration: 1.2,
            height: "100%",
            ease: Power3.easeInOut,
        });
        tl.to(screen, {
            duration: 1,
            bottom: "100%",
            ease: Power3.easeInOut,
            delay: 0.3,
        });
        
        function animateBox(fromBoxtoBox) {
            var clone = fromBox.cloneNode(true);
            var from = posOfBox(fromBox);
            var to = posOfBox(toBox);

            TweenLite.set([fromBoxtoBox], { visibility: "hidden" });
            TweenLite.set(clone, { position: "absolute"margin: 0 });

            body.appendChild(clone);

            var style = {
                x: to.left - from.left,
                y: to.top - from.top,
                width: to.width,
                height: to.height,
                autoRound: false,
                ease: Power1.easeOut,
                onComplete: onComplete
            };

            TweenLite.set(clonefrom);
            TweenLite.to(clone0.3style)

            function onComplete() {

                TweenLite.set(toBox, { visibility: "visible" });
                body.removeChild(clone);
            }
        }

     TweenMax.to(body2.3, {
            css: {
                opacity: "1",
                pointerEvents: "auto",
                ease: Power4.easeInOut
            }
        }).delay(2);
        return () => {
            TweenMax.to(body21, {
                css: {
                    opacity: "0",
                    pointerEvents: "auto",
                }
            });
        }
    }, []);
Previous Post Next Post