Giter Club home page Giter Club logo

react-gsap-utils's Introduction

React GSAP Utils

Collection of zero-config, drop-in utilities to animate React elements and components using GSAP. Supports all GSAP Tween animation props.

See the DEMO on Codepen

  • ๐Ÿ‘๐Ÿป Zero-config, easy to use
  • ๐Ÿ‘Œ๐Ÿป No dependencies, only 16KB unpacked size
  • ๐Ÿงฉ Fully written in TypeScript
  • โœ… Compatible with existing GSAP's ScrollSmoother, ScrollTriggers in your project

Installation

npm install @lynksen/react-gsap-utils

Usage

1. Animate On Mount

Easily animate any custom elements mount/unmount based on conditional rendering.

  • param {Object} props - The component props.
  • param {React.ReactNode} props.children - The children to be animated.
  • param {boolean} props.mounted - Determines whether the component is mounted or not.
  • param {string} props.className - The CSS class name for the component.
  • param {Array} props.fromTo - The animation configuration for the component.
  • param {number} props.fromTo[].opacity - The initial opacity value.
  • param {number} props.fromTo[].y - The initial y-axis position.
  • param {number} props.fromTo[].duration - The duration of the animation.
  • param {string} props.fromTo[].ease - The easing function for the animation.
  • returns {React.ReactElement} The rendered component.
  • import { AnimateOnMount } from "@lynksen/react-gsap-utils";
    
    <AnimateOnMount
        mounted={condition}
        fromTo={[
          { opacity: 0, y: "60%" },
          { opacity: 1, y: "0%" },
        ]}
    >
      <YourCustomElement>
       <p>Animating mount and unmount on condition change</p>
      </YourCustomElement>
    </AnimateOnMount>
    

    2. Animate On Scroll

    A no-config ScrollTrigger component for children reveal animation.

    • @param children - The content to be animated.
    • @param int YOffset - The offset in percentage from the top of the viewport where the animation should start.
    • @param from - The initial animation properties (as in gsap.from())
    • @param string className - Additional class name for the container.
    • @param childClassName - Additional class name for the child element.
    • @param onComplete - Callback function to be called when the animation completes.
    • @param onStart - Callback function to be called when the animation starts.
    • @param debug - Whether to show debug markers during animation.
    import { AnimateOnScroll } from "@lynksen/react-gsap-utils";
    
    <AnimateOnScroll
    >
      <YourCustomElement>
       <p>Revealing and disappearing according to the scroll animation defined.</p>
      </YourCustomElement>
    </AnimateOnScroll>
    

    Caveats

    • โš ๏ธ Compatibility with custom scroll smoothing libraries may not be possible.

    License

    MIT.

react-gsap-utils's People

Contributors

lynksendymytrii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.