43
Between.js: Modern ES6 Tweening Library / NPM [8.3Kb]
source link: https://www.tuicool.com/articles/hit/jA777fM
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Lightweight JavaScript (ES6) tweening library.
EXAMPLES
DOCUMENTATION
Purpose
Make twining usage convenient and powerful.
Install with npm
$ npm install between.js
Basic usage
import Between from 'between.js'; new Between(1, 10).time(1000) .on('update', (value) => { 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>
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('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); });
Arrays
import Between from 'between.js'; new Between([1, 5], [10, 10]).time(1000) .on('update', (value) => { console.log(value); });
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); });
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); });
Repeat endless
import Between from 'between.js'; new Between(1, 10).time(4000) .loop('repeat') .on('update', (value) => { console.log(value); });
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); });
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); });
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); });
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'; // 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); });
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK