All Projects → sasha240100 → Between.js

sasha240100 / Between.js

Licence: mit
Lightweight JavaScript (ES6) tweening engine

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects

Projects that are alternatives of or similar to Between.js

Moveto
A lightweight scroll animation javascript library without any dependency
Stars: ✭ 2,746 (+290.61%)
Mutual labels:  lightweight, smooth
Microsocks
tiny, portable SOCKS5 server with very moderate resource usage
Stars: ✭ 549 (-21.91%)
Mutual labels:  lightweight
React Select Search
⚡️ Lightweight select component for React
Stars: ✭ 379 (-46.09%)
Mutual labels:  lightweight
Oio Sds
High Performance Software-Defined Object Storage for Big Data and AI, that supports Amazon S3 and Openstack Swift
Stars: ✭ 465 (-33.85%)
Mutual labels:  lightweight
Markdowneditor
Lightweight markdown editor written for windows,only one GREEN exe file
Stars: ✭ 403 (-42.67%)
Mutual labels:  lightweight
Ganalytics
A tiny (312B) client-side module for tracking with Google Analytics
Stars: ✭ 491 (-30.16%)
Mutual labels:  lightweight
Espnetv2
A light-weight, power efficient, and general purpose convolutional neural network
Stars: ✭ 377 (-46.37%)
Mutual labels:  lightweight
Handright
A lightweight Python library for simulating Chinese handwriting
Stars: ✭ 634 (-9.82%)
Mutual labels:  lightweight
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-23.33%)
Mutual labels:  lightweight
Qview
Practical and minimal image viewer
Stars: ✭ 460 (-34.57%)
Mutual labels:  lightweight
Litepicker
Date range picker - lightweight, no dependencies
Stars: ✭ 442 (-37.13%)
Mutual labels:  lightweight
Nier Visualizer
A lightweight and efficient Android visual library.
Stars: ✭ 421 (-40.11%)
Mutual labels:  lightweight
Superslide.js
A flexible, smooth, GPU accelerated sliding menu for your next PWA
Stars: ✭ 496 (-29.45%)
Mutual labels:  smooth
Offen
The fair and lightweight alternative to common web analytics tools.
Stars: ✭ 385 (-45.23%)
Mutual labels:  lightweight
Domvm
DOM ViewModel - A thin, fast, dependency-free vdom view layer
Stars: ✭ 581 (-17.35%)
Mutual labels:  lightweight
Flashdb
An ultra-lightweight database that supports key-value and time series data | 一款支持 KV 数据和时序数据的超轻量级数据库
Stars: ✭ 378 (-46.23%)
Mutual labels:  lightweight
Embassy
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux
Stars: ✭ 440 (-37.41%)
Mutual labels:  lightweight
Astroid
A graphical threads-with-tags style, lightweight and fast, e-mail client for Notmuch
Stars: ✭ 476 (-32.29%)
Mutual labels:  lightweight
Tinynvidiaupdatechecker
Check for NVIDIA GPU driver updates!
Stars: ✭ 675 (-3.98%)
Mutual labels:  lightweight
Elegantrl
Lightweight, efficient and stable implementations of deep reinforcement learning algorithms using PyTorch.
Stars: ✭ 575 (-18.21%)
Mutual labels:  lightweight

Lightweight JavaScript (ES6) tweening library.

NPM

EXAMPLES

DOCUMENTATION

Purpose

Make tweening usage convenient and powerful. There are certain things that we were following while developed this library, we wanted to make it:

  • Lightweight ❄️ JS Tweening library.

The library is only 9.08 Kb (3Kb gzip)

  • Performant ⚡️ JS Tweening library.

It uses optimization patterns to speed up & smooth animation.

  • Modern 💎 JS Tweening library

The library is written in ES6, compiled to ES5 for global browsers support and provides ES6 API.

Install

With npm

$ npm install between.js

Or fetch from CDN

<script src="https://rawgit.com/sasha240100/between.js/master/build/between.js"></script>

Basic usage

Module

import Between from 'between.js';

// new Between(from, to).time(duration)
new Between(1, 10).time(1000)
  .on('update', (value) => { // This callback is executed in every frame
      console.log(value);
  });

Or in HTML:

<script src="./path/to/between.js"></script>
<script>
  new Between(1, 10).time(1000)
    .on('update', (value) => {
        console.log(value);
    });
</script>

API

// Constructor
new Between(
 [Number|Object|Array] from, 
 [Number|Object|Array] to
)

// Methods
  .time([Number] duration) // Set duration
  .loop([String] mode, [?Number] repeatTimes) // Set loop mode, if "repeatTimes" is falsy, treats as "endless"
  .easing([Function] easing) // Set easing function
  .on([String] eventName, [Function] callback) // Add event listener
  .pause() // Pauses
  .play() // Resumes

// Getters
  .isPaused // returns true if paused

There is no need to "start" the tween. It is executed immediately once it was created.

Events

import Between from 'between.js';

new Between(1, 10).time(1000)
  .on('update', (value) => {
      console.log(value); 
  })
  .on('start', (value) => {
      console.log(value);
  })
  .on('pause', (value) => {
      console.log(value); 
  })
  .on('play', (value) => {
      console.log(value);
  })
  .on('complete', (value) => {
      console.log(value);
  });

Different values

  • Numbers
  • Arrays
  • Objects

Numbers

import Between from 'between.js';

new Between(1, 10).time(1000)
  .on('update', (value) => {
      console.log(value);
  });

Example

Arrays

import Between from 'between.js';

new Between([1, 5], [10, 10]).time(1000)
  .on('update', (value) => {
      console.log(value);
   });

Example

Objects

import Between from 'between.js';

new Between({x: 2, y: 3, z: 4}, {x: 4, y: 6, z: 10}).time(1000)
  .on('update', (value) => {
      console.log(value);
  });

Example

Looping

Repeat N times

import Between from 'between.js';

new Between(1, 10).time(4000)
  .loop('repeat', N)
  .on('update', (value, {times}) => {
      console.log(value);
      console.log(times);
  });

Example

Repeat endless

import Between from 'between.js';

new Between(1, 10).time(4000)
  .loop('repeat')
  .on('update', (value) => {
      console.log(value);
  });

Example

Bounce N times

import Between from 'between.js';

new Between(1, 10).time(4000)
  .loop('bounce', N)
  .on('update', (value, {times}) => {
      console.log(value);
      console.log(times);
  });

Example

Easing

import Between from 'between.js';
import Easing from 'easing-functions';

// choose easing mode frome easing-functions

new Between(1, 10).time(4000)
  .easing(Between.Easing.Cubic.InOut)
  .on('update', (value) => {
      console.log(value);
  });

Example

easing-functions npm

Color

Color types:

  • HEX
  • HSL
  • RGB
  • Words (red, yellow...)
import Between from 'between.js';
import ColorPlugin from 'between.js/build/dom-color.between.js';

Between._plugins.color = ColorPlugin;

new Between('red', 'rgb(255,40,30)').time(4000)
  .on('update', (value) => {
      console.log(value);
  });

Example

Or in HTML:

<script src="./path/to/between.js"></script>
<script src="./path/to/dom-color.between.js"></script>

Mixed examples

import Between from 'between.js';
import Easing from 'easing-functions';
import ColorPlugin from 'between.js/build/dom-color.between.js';

Between._plugins.color = ColorPlugin;

// choose easing mode frome easing-functions

new Between('red', 'rgb(255,40,30)').time(4000)
  .loop('repeat', 3)
  .easing(Between.Easing.Linear)
  .on('update', (value) => {
      console.log(value);
  });
import Between from 'between.js';
import Easing from 'easing-functions';

// choose easing mode frome easing-functions

new Between(1, 10).time(4000)
  .loop('bounce', 3)
  .easing(Between.Easing.Cubic.InOut)
  .on('update', (value) => {
      console.log(value);
  });
import Between from 'between.js';
import Easing from 'easing-functions';

// choose easing mode frome easing-functions

new Between(1, 10).time(4000)
  .loop('repeat', 4)
  .easing(Between.Easing.Elastic.In)
  .on('update', (value) => {
      console.log(value);
  })
  .on('complete', (value) => {
      console.log(value);
  });
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].