项目作者: DEGJS

项目描述 :
Javascript animation easing functions
高级语言: JavaScript
项目地址: git://github.com/DEGJS/easing.git
创建时间: 2016-06-20T23:53:55Z
项目社区:https://github.com/DEGJS/easing

开源协议:

下载


Easing

Run Tests

A collection of animation easing functions in Javascript’s ES6 module format. Easing functions specify the rate of change of a parameter over time. Learn more about easing here.

Install

Easing is an ES module. If your runtime environment does not support ES modules, you’ll need a transpiler (Babel is a nice one).

If you’re using NPM, you can install Easing with the following command:

  1. $ npm install @degjs/easing

Usage

  1. import { easeInOutCubic } from '@degjs/easing';
  2. // animate a value from 100 to 300 with ease-in-out easing over the course of 1 second
  3. let currentIteration = 0,
  4. totalIterations = 60,
  5. startValue = 100,
  6. changeInValue = 200,
  7. easedValue;
  8. window.requestAnimationFrame(onAnimationFrame);
  9. function onAnimationFrame() {
  10. if(currentIteration < totalIterations) {
  11. currentIteration++;
  12. easedValue = easeInOutCubic(currentIteration, startValue, changeInValue, totalIterations);
  13. }
  14. }

Methods

All methods take the same four parameters, defined below:

currentIteration

Type: Number
The current iteration. Think of this in terms of animation frames or seconds/milliseconds.

startValue

Type: Number
The start value. This is the initial state of the value that will be animated.

changeInValue

Type: Number
The amount of change in the value over the duration of the animation.

totalIterations

The duration of the animation. Think of this in terms of animation frames or seconds/milliseconds.

.linear(currentIteration, startValue, changeInValue, totalIterations)

A linear rate of change with no easing.

.easeOutCubic(currentIteration, startValue, changeInValue, totalIterations)

Starts quickly and ends slowly.

.easeInCubic(currentIteration, startValue, changeInValue, totalIterations)

Starts slowly and ends quickly.

.easeInOutCubic(currentIteration, startValue, changeInValue, totalIterations)

Starts and ends slowly.