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

spring-chain

v1.0.4

Published

SpringChain is a versatile JavaScript animation library designed to bring your UI elements to life with smooth, physics-based spring animations. Leveraging the power of the Web Animations API and a robust spring physics engine, SpringChain allows develope

Downloads

36

Readme

springchain

Description

This is a simple library that allows you to chain multiple animations together in a Spring-like fashion. It uses Hooke's law to calculate the spring force and the damping force. The library is written in vanilla JavaScript and can be used in any project as long as you include or import the script in your HTML file.

Installation

To install the library, you can either download the script from the dist folder or use the npm package manager to install it. To install the library using npm, run the following command:

# Using npm package manager
npm install spring-chain

# Using yarn package manager
yarn add spring-chain

Usage

To use the library, you need to include the script in your HTML file or import import 'spring-chain' it in your JavaScript file. Here is an example of how you can use the library to chain multiple animations together in vanilla JavaScript:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>SpringChain Example</title>
  </head>

  <body>
    <div id="box" style="width: 100px; height: 100px; background-color: red;"></div>

    <script>
      const box = document.getElementById("box")

      // Rotation animation
      box.motion({
        spring: {
          stiffness: 20, // Lower stiffness means more springy
          damping: 5, // Lower damping means more bouncy
          mass: 1, // Lower mass means more bouncy
        },
        rotate: 360, // Rotate 360 degrees
        delay: 500, // Delay (x)ms before starting this animation
      })

      // Scale animation
      box.motion({
        spring: {
          stiffness: 20,
          damping: 5,
          mass: 1,
        },
        scale: 2, // Scale to 2x
      })
    </script>
    <script src="path/to/springChain.umd.js"></script>
  </body>
</html>

Using ES Module Import

Example:

import "spring-chain"

// Use the library function
document.querySelector("div").motion({ x: 100, y: 100, scale: 1.5 })

API

The library provides a single method called motion that you can use to chain multiple animations together. The motion method takes an object as an argument with the following properties:

  • spring: An object that contains the spring properties such as stiffness, damping, and mass.
  • ...keyframes: The keyframes can be any CSS properties such as rotate, scale, x, y, etc.
  • delay: The delay (in milliseconds) before starting the animation.

Here is an example of how you can use the motion method:

const box = document.getElementById("box")

box.motion({
  spring: {
    stiffness: 20,
    damping: 5,
    mass: 1,
  },
  rotate: 360,
  delay: 500,
})

Chain API

You can chain multiple animations together by calling the motion method multiple times. The library will automatically chain the animations together in a Spring-like fashion. Here is an example of how you can chain multiple animations together:

const box = document.getElementById("box")

box
  .motion({
    rotate: 360,
    delay: 500,
  })
  .motion({
    spring: {
      stiffness: 20,
      damping: 5,
      mass: 1,
    },
    scale: 2,
  })
  .motion({
    spring: {
      stiffness: 20,
      damping: 5,
      mass: 1,
    },
    x: 360,
  })

License

This library is licensed under the MIT license. You can find the full license text in the LICENSE file.

Author

This library is created by Dev ByLucas.

Contributing

If you would like to contribute to this library, feel free to create a pull request or open an issue on the GitHub repository.