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

jeasings

v0.0.16

Published

A JavaScript module for extrapolating numerical values over time

Downloads

1,044

Readme

JEASINGS

A JavaScript module for extrapolating numerical values over time.

[!NOTE] JEASINGS API based on Tween.js release 1 : https://github.com/sole/tween.js/blob/r1/src/Tween.js

See Tween.js r1 License at https://github.com/sole/tween.js/blob/r1/LICENSE

Usage

CDN

import JEASINGS from 'https://esm.sh/jeasings'

NPM

npm install jeasings
import JEASINGS from 'jeasings'

Host Locally

import JEASINGS from '/path/to/JEasings.js'

Basic Example

Using the JEASINGS module to animate a HTML div position.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>JEASINGS Module</title>
    <meta name="description" content="Using the JEASINGS module to animate a Div position." />
    <style>
      body {
        overflow: hidden;
        margin: 0px;
        background-color: #0f0f0f;
      }

      #box {
        background-color: hotpink;
        position: absolute;
        width: 100px;
        height: 100px;
      }
    </style>
  </head>
  <body>
    <div id="box"></div>
    <script type="module">
      import JEASINGS from 'https://esm.sh/jeasings'

      const position = { x: 0, y: 0 } // Starting position.

      new JEASINGS.JEasing(position) // Create a new JEasing that modifies the 'position' object.
        .to({ x: 500, y: 250 }, 1500) // Move to (500, 250) in one and a half seconds.
        .start() // Start the JEasing.

      function animate() {
        requestAnimationFrame(animate)

        JEASINGS.update() // Update JEASINGS in an animation loop.

        // Update Box position after JEASINGS were re-evaluated.
        box.style.left = position.x + 'px'
        box.style.top = position.y + 'px'
      }
      animate()
    </script>
  </body>
</html>

Edit on SBEDIT

Add a Starting Delay

new JEASINGS.JEasing(position)
  .to({ x: 500, y: 250 }, 1500)
  .delay(500) // Optional. Delay half a second before starting the JEasing.
  .start()

Edit on SBEDIT

Use a Curve Function

The default JEasing will run and finish at a constant speed. We can modify the speed as it progresses through the duration by setting the easing option.

new JEASINGS.JEasing(position)
  .to({ x: 500, y: 250 }, 1500)
  .delay(500)
  .easing(JEASINGS.Quadratic.InOut) // Optional. Use can use a curve function to change the speed over time.
  .start()

Edit on SBEDIT

See more JEasing Curve Functions

JEasing onUpdate callback.

We can run some code everytime a JEasing is re-evaluated. Example, we could update the Boxes position in the onUpdate callback instead of in the animation loop.

new JEASINGS.JEasing(position)
  .to({ x: 500, y: 250 }, 1500)
  .delay(500)
  .easing(JEASINGS.Quadratic.InOut)
  .onUpdate(() => {
    // Optional. Every time the JEasing is updated, do something such as re-position the box.
    box.style.left = position.x + 'px'
    box.style.top = position.y + 'px'
  })
  .start()

function animate() {
  requestAnimationFrame(animate)

  JEASINGS.update()

  // box.style.left = position.x + 'px'
  // box.style.top = position.y + 'px'
}
animate()

Edit on SBEDIT

JEasing onComplete callback.

When a JEasing completes, we can run another script. E.g, start a new JEasing.

new JEASINGS.JEasing(position)
  .to({ x: 500, y: 250 }, 1500)
  .delay(500)
  .easing(JEASINGS.Quadratic.InOut)
  .onUpdate(() => {
    box.style.left = position.x + 'px'
    box.style.top = position.y + 'px'
  })
  .onComplete(() => {
    // In the onComplete callback we can run any script.
    new JEASINGS.JEasing(position)
      .to({ x: 0, y: 0 }, 1500)
      .easing(JEASINGS.Bounce.Out)
      .onUpdate(() => {
        box.style.left = position.x + 'px'
        box.style.top = position.y + 'px'
      })
      .start()
  })
  .start()

Edit on SBEDIT

JEasings as Variables

You can create JEasings as variables first, and then start them later as needed.

const part1 = new JEASINGS.JEasing(position)
  .to({ x: 500, y: 250 }, 1500)
  .delay(500)
  .easing(JEASINGS.Quadratic.InOut)
  .onComplete(() => {
    part2.start() // When completed, start the part2 JEasing
  })
//.start()

const part2 = new JEASINGS.JEasing(position)
  .to({ x: 0, y: 0 }, 1500)
  .easing(JEASINGS.Bounce.Out)
  .onComplete(() => {
    part1.start() // Go back to the part1 JEasing
  })
//.start()

part1.start() // Start the JEasing chain execution.

function animate() {
  requestAnimationFrame(animate)

  JEASINGS.update()

  box.style.left = position.x + 'px'
  box.style.top = position.y + 'px'
}
animate()

Edit on SBEDIT

Chained JEasings

Another way of chaining JEasings is to use the chain() method. Create several JEasings as varibles, and then use the chain keyword to sequence them. Then start one of them to begin the chain sequence.

const slideRight = new JEASINGS.JEasing(position).to({ x: 500, y: 0 }, 1000)

const slideDown = new JEASINGS.JEasing(position).to({ x: 500, y: 200 }, 1000)

const slideLeft = new JEASINGS.JEasing(position).to({ x: 0, y: 200 }, 1000)

const slideUp = new JEASINGS.JEasing(position).to({ x: 0, y: 0 }, 1000)

slideRight.chain(slideDown)
slideDown.chain(slideLeft)
slideLeft.chain(slideUp)
slideUp.chain(slideRight)

slideRight.start() // Start the JEasing chain.

Edit on SBEDIT

JEasing Destructuring

Instead of creating new JEasings using the syntax new JEASINGS.Jeasing(...), you can destructure parts of the library into single variables.

E.g.,

import JEASINGS from '/jeasings/JEasings.js'

const { JEasing, Bounce } = JEASINGS // Destructure only what you need.

const position = { x: 0, y: 0 }

const slideRight = new JEasing(position).to({ x: 500, y: 0 }, 1000).easing(Bounce.Out)

Edit on SBEDIT

Named Imports

Instead of destructuring the JEASINGS imports, you can also used named imports for only what you need.

E.g.,

import JEASINGS, { JEasing, Bounce } from '/jeasings/JEasings.js'

const position = { x: 0, y: 0 }

const slideRight = new JEasing(position).to({ x: 500, y: 0 }, 1000).easing(Bounce.Out)

Edit on SBEDIT

JEasing Curve Functions

E.g., .easing(JEASINGS.Quadratic.InOut)

JEasing Curve Functions

More Examples

Jeasings Easings

JEasing Chain

JEasing OrbitControls

Kick Boxing

House (CDN Example)

JEasing Latitude Longitude

JEasing OrbitControls Target in R3F

MapControls with Select Object to Zoom in

Rubiks Cube

Raycast to a Displacement Map

Three.js css3d - periodic table using JEASINGS

Three.js css3d - sprites using JEasings

Three.js webgl - collada - kinematics using JEasings