Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iamcal/ease.js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iamcal/ease.js

Easing in JavaScript

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ease.js - Easing in JavaScript

NPM version NPM downloads 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.

Keywords

FAQs

Package last updated on 18 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc