npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terrahq/reveal-it

v1.0.16

Published

Javascript module for animate elements written in Vanilla js.

Downloads

29

Readme

@terrahq/reveal-it

Javascript module for animate elements written in Vanilla js.

Usage

Install

npm install @terrahq/reveal-it

Import

import RevealIt from "@terrahq/reveal-it";

Initialize

JS

 let example = new RevealIt({
        element: document.querySelector('.js--reveal-it'),
        // Optional: Customize options here
    });

Directly in Browser (CDN)

You can also use @terrahq/reveal-it directly in your browser without installing it, by including it from UNPKG. This is useful for quick prototypes or projects where you are not using a build system like Webpack or Rollup.

Add the following <script> tags to your HTML to include @terrahq/reveal-it and its GSAP dependency directly in your browser using:

 <!-- GSAP (required by @terrahq/reveal-it) -->
 <script src="https://unpkg.com/gsap@latest"></script>
 <!-- @terrahq/reveal-it -->
 <script src="https://unpkg.com/@terrahq/reveal-it@latest/dist/reveal-it.umd.js"></script>

These script tags will load the latest versions of GSAP, the ScrollTrigger plugin, and @terrahq/reveal-it

Markup

Minimum markup

<div class="js--reveal-it">
    <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit.
        Ea deleniti nisi maxime sequi corporis labore repellat impedit,
        id vel, esse ad, culpa praesentium? Nobis quam fugiat natus,
        at nisi cumque.
    </p>
</div>

Initialize with options

Besides options you can also add the animation type. By default it's 'from', but you can change it to 'to' or 'fromTo'.

JS

const example = document.querySelector(".js--reveal-it-w-options");
const revealWithCallbacks = new RevealIt({
    element: example,
    type: "from", //it's 'from' by default but you can change it to 'to' or 'fromTo'
    options: {
        duration: 1,
        opacity: 0,
        yoyo: false,
        repeat: 2,
        onStart: function () {
            example.classList.remove('animation-completed');
            example.classList.add('animation-started');
        },
        onComplete: function () {
            example.classList.add('animation-completed');
            example.classList.remove('animation-started');
        },
    }
});

Options

| Option Name | Type | Default | Desc | |-------------------|------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------| | opacity | number | - | Initial opacity of the element before the animation starts. | | duration | number | 1 | Duration of the animation in seconds. | | rotate | number | - | Degrees to rotate the element. Not set by default. | | scale | number | - | Factor by which to scale the element. Not set by default. | | y | number | - | Vertical movement in pixels. Not set by default. | | x | number | - | Horizontal movement in pixels. Not set by default. | | repeat | number | - | Number of times the animation repeats. -1 for infinite. | | ease | string | "none" | GSAP easing function to control animation pacing. | | scrollTrigger | object | start: "top center", markers: false, toggleActions: 'play pause resume pause', | Configuration object for GSAP's ScrollTrigger plugin. | | onStart | function | | Callback function that runs at the start of the animation. | | onComplete | function | | Callback function that runs upon completion of the animation. |

Responsive Animation Example with Breakpoints

This example demonstrates how to use RevealIt to create responsive animations that behave differently based on the viewport size. By specifying breakpoint options, you can define unique animation behaviors for various screen sizes.

Example Code

// Define breakpoint options for responsive animations
const breakpointOptionsScroll = {
    largerScreen: {
        minWidth: 'tablets',
        animationOptions: {
            opacity: 1,
            duration: 1,
            x: 100,
            yoyo: true,
            repeat: -1,
            scrollTrigger: {
                trigger: ".box3",
                start: "top center",
                toggleActions: 'play none none none',
            },
            onStart: () => console.log("Animation started on larger screens"),
            onComplete: () => console.log("Animation completed on larger screens"),
        }
    },
    smallerScreen: {
        maxWidth: 'tablets',
        animationOptions: {
            opacity: 0.5,
            duration: 1.5,
            y: 100,
            yoyo: false,
            scrollTrigger: {
                trigger: ".box3",
                start: "top center+=100",
                toggleActions: 'play none none none',
            },
            onStart: () => console.log("Animation started on smaller screens"),
            onComplete: () => console.log("Animation completed on smaller screens"),
        }
    }
};

// Initialize RevealIt with the defined breakpoint options
const box3Reveal = new RevealIt({
    element: document.querySelector('.box3'),
    animateOnMobile: true,
    breakpointOptions: breakpointOptionsScroll
});

Breakpoints

Breakpoints in the configuration are referenced by string names. The corresponding pixel values for each named breakpoint are as follows:

const breakpoints = [
    { 'mobile': 580 },
    { 'tablets': 810 },
    { 'tabletm': 1024 },
    { 'tabletl': 1300 },
    { 'laptop': 1570 },
    { 'desktop': 1700 }
];

Methods

getAnimation()

Retrieves the GSAP animation instance for further manipulation. This allows direct access to GSAP's animation methods such as .restart(), .pause(), .play(), and more.

Usage

// If we want to restart the animation
revealit.getAnimation().restart;

refresh()

Refreshes the ScrollTrigger instance associated with the animation. This method is useful when the DOM changes in a way that affects the size or position of the animated element, ensuring the scroll animations remain accurate.

Usage

revealit.refresh();

destroy()

Destroys the ScrollTrigger instance linked to the animation, effectively removing the scroll-triggered behaviors and listeners. Use this method to clean up when an animation is no longer needed to prevent memory leaks and ensure optimal performance.

Usage

revealit.destroy();

License