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 🙏

© 2025 – Pkg Stats / Ryan Hefner

zing-animation

v1.0.6

Published

A lightweight animation library inspired by GSAP and Framer Motion

Downloads

12

Readme

# Zing Animation Library

Zing is a lightweight animation library for both **Vanilla JavaScript** and **React**, inspired by GSAP and Framer Motion. It provides a powerful, clean API to animate DOM elements or React components using both **imperative** and **declarative** approaches.

## Table of Contents

1. [Installation](#installation)
2. [Core Concepts](#core-concepts)
3. [Vanilla JavaScript Usage](#vanilla-javascript-usage)
4. [React Usage](#react-usage)
   - [ZingComponent](#zingcomponent)
   - [useAnimation Hook](#useanimation-hook)
5. [Animation Properties](#animation-properties)
6. [Easing Functions](#easing-functions)
7. [Advanced Patterns](#advanced-patterns)
8. [Troubleshooting](#troubleshooting)

---

## Installation

Install via npm or yarn:

```bash
npm install zing-animation
# or
yarn add zing-animation

Note: If you encounter a dependency issue related to React versions (especially with React 19+), use the following command to bypass strict peer dependency resolution:

npm install zing-animation --legacy-peer-deps

Core Concepts

Zing Animation supports two paradigms:

  • Imperative API – Direct control over animation via functions (for Vanilla JS).
  • Declarative API – React components and hooks for more expressive animation flows.

Vanilla JavaScript Usage

Basic Animation

import { zing } from 'zing-animation';

const element = document.getElementById('my-element');

// Animate to new values
zing.to(element, {
  x: 100,
  opacity: 0.5,
  duration: 1,
  ease: 'easeOut',
  onComplete: () => console.log('Animation complete!')
}).play();

// Animate from values
zing.from(element, {
  x: -100,
  opacity: 0,
  duration: 0.5
}).play();

// Chained animations
zing.to(element, { x: 100, duration: 0.5 })
   .to(element, { y: 50, duration: 0.5 })
   .play();

Animation Controls

const animation = zing.to(element, { x: 100 });

animation.play();
animation.pause();
animation.restart();

// Timeline
const timeline = zing.sequence();
timeline.add(zing.to(element1, { x: 100 }));
timeline.add(zing.to(element2, { y: 50 }));
timeline.play();

React Usage

ZingComponent

A declarative component for defining entry/exit animations:

import { ZingComponent } from 'zing-animation';

function MyComponent() {
  return (
    <ZingComponent
      initial={{ opacity: 0, scale: 0.5 }}
      animate={{ opacity: 1, scale: 1 }}
      transition={{ duration: 0.5, ease: 'easeOut' }}
      style={{ width: 100, height: 100, background: 'blue' }}
    >
      Animated Content
    </ZingComponent>
  );
}

useAnimation Hook

Hook for full animation control inside components:

import { useAnimation } from 'zing-animation';

function MyComponent() {
  const ref = useRef();

  // Simple animation
  useAnimation(ref, {
    from: { opacity: 0 },
    to: { opacity: 1, x: 100 }
  });

  // Callback-based dynamic animation
  useAnimation(ref, () => ({
    from: { opacity: 0, y: -20 },
    to: { opacity: 1, y: 0, duration: 0.8, onComplete: () => console.log('Done!') }
  }));

  return <div ref={ref}>Animated Element</div>;
}

Animation Properties

Transform Properties

  • x: Horizontal translation (px)
  • y: Vertical translation (px)
  • scale: Scaling (number)
  • rotate: Rotation (deg)
  • skewX, skewY: Skew transforms (deg)

Style Properties

  • opacity
  • width, height
  • backgroundColor
  • color
  • Any other animatable CSS property

Controls

  • duration (seconds, default 0.5)
  • delay (seconds)
  • ease (see Easing Functions)
  • onComplete (callback)
  • repeat (number)
  • yoyo (boolean, reverse on repeat)

Easing Functions

Zing provides a variety of easing presets:

  • linear
  • easeIn, easeOut, easeInOut
  • easeInCubic, easeOutCubic
  • easeInElastic, easeOutElastic
  • easeInBack, easeOutBack
<ZingComponent
  animate={{ x: 100 }}
  transition={{ ease: 'easeOutBack' }}
/>

Advanced Patterns

Staggered Animations

function List() {
  const items = [1, 2, 3, 4];
  const refs = items.map(() => useRef());

  useEffect(() => {
    refs.forEach((ref, i) => {
      zing.to(ref.current, {
        x: 100,
        opacity: 1,
        delay: i * 0.1,
        duration: 0.5
      }).play();
    });
  }, []);

  return (
    <div>
      {items.map((item, i) => (
        <div key={item} ref={refs[i]} style={{ opacity: 0 }}>
          Item {item}
        </div>
      ))}
    </div>
  );
}

Scroll-triggered Animations

function ScrollComponent() {
  const ref = useRef();

  useEffect(() => {
    const onScroll = () => {
      const rect = ref.current.getBoundingClientRect();
      const progress = Math.min(rect.top / window.innerHeight, 1);

      zing.to(ref.current, {
        x: progress * 100,
        opacity: 1 - progress
      }).play();
    };

    window.addEventListener('scroll', onScroll);
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  return <div ref={ref}>Scroll me!</div>;
}

Troubleshooting

Animation Not Working?

  • Ensure elements are visible and styled correctly.
  • Avoid conflicting styles (overflow: hidden on parents may hide animations).
  • Use camelCase CSS properties (e.g. backgroundColor).

Performance Issues?

  • Use transform properties (x, y, scale) over layout props (margin, width).
  • Add will-change: transform in CSS for smoother animations.
  • Avoid animating large numbers of elements simultaneously.

React Warnings or Errors?

  • Always use useEffect for side-effects like animations.
  • Clean up listeners or animations inside the useEffect return.
  • Use useCallback when passing animation functions as dependencies.

📦 Links


Created with ❤️ to bring motion to the web.