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

@iamcal/ease.js

v0.0.3

Published

Easing in JavaScript

Downloads

5

Readme

ease.js - Easing in JavaScript

Build Status Coverage Status

When an object changes position in real life, it rarely moves linearly. It can start slow, speed up, slow down, then come to rest. This is called easing.

This library provides easing functions for producing natural-looking animations in JavaScript.

For more on easing in general, see Robert Penner's page.

Usage

From Node, load as a module:

var Ease = require('./lib/ease.js');

From the browser, just include the script:

<script src="./lib/ease.js"></script>

Once loaded, you can create a new instance of the Ease object to start using it. You can pass in an easing algorithm to use (see below for a list of supported choices), otherwise it will default to easeInOutSine.

var myEase = new Ease('easeInSine');

The most straight forward way to use the object is to call .run(), which will call your passed-in callback to allow you to animate your objects. A single argument is passed to the callback, a value between 0 (at the start) and 1 (at the end). For some algorithms, values below 0 or above 1 can be returned (e.g. for overshooting).

var callback = function(x){ console.log(x); }; // called on each iteration
var duration = 1; // duration in seconds
var fps = 30; // frames per second

myEase.run(callback, duration, fps);

If you're performing animations in a modern browser that supports window.requestAnimationFrame, then you can use the .runRAF() method to sync your changes to frame updates, for a smoother result.

myEase.runRAF(callback, duration);

If you want to handle the timing yourself, you can call the .interpolate() method, which just runs the selected easing algorithm. Pass in a value between 0 and 1 (representing the absolute progress of the animation) and get back the mapped value.

function iterateDiv(x){
    var y = myEase.interpolate(x);
    moveDiv(y * 100);
}

Supported easing functions

We support 30 easing functions, 3 variations (in, out and in-out) for each of 10 approaches. You can read more about each easing function at https://easings.net/.

  • Sine functions - easeInSine, easeOutSine, easeInOutSine
  • Quadratic functions - easeInQuad, easeOutQuad, easeInOutQuad
  • Cubic functions - easeInCubic, easeOutCubic, easeInOutCubic
  • Quartic functions - easeInQuart, easeOutQuart, easeInOutQuart
  • Quintic functions - easeInQuint, easeOutQuint, easeInOutQuint
  • Exponential functions - easeInExpo, easeOutExpo, easeInOutExpo
  • Circular functions - easeInCirc, easeOutCirc, easeInOutCirc
  • Pull-back functions - easeInBack, easeOutBack, easeInOutBack
  • Elastic functions - easeInElastic, easeOutElastic, easeInOutElastic
  • Bounce functions - easeInBounce, easeOutBounce, easeInOutBounce

You can get an array of supported algorithms via the .algorithms() method.

In the future, I may add support for further functions, with tunable parameters, similar to d3-ease.