UNPKG

animate-value

Version:
171 lines (116 loc) • 4.31 kB
# animate-value > šŸƒ animates a numeric value ![Node](https://img.shields.io/node/v/animate-value.svg?style=flat-square) [![NPM](https://img.shields.io/npm/v/animate-value.svg?style=flat-square)](https://www.npmjs.com/package/animate-value) [![David](https://img.shields.io/david/duivvv/animate-value.svg?style=flat-square)](https://david-dm.org/duivvv/animate-value) [![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20šŸ˜-FFDD67.svg?style=flat-square)](https://gitmoji.carloscuesta.me/) ### Installation Install via [yarn](https://github.com/yarnpkg/yarn) yarn add animate-value (--dev) or npm npm install animate-value (--save-dev) If you don't use a package manager, you can [access `animate-value` via unpkg (CDN)](https://unpkg.com/animate-value/), download the source, or point your package manager to the url. `animate-value` is compiled as a collection of [CommonJS](http://webpack.github.io/docs/commonjs.html) modules & [ES2015 modules](http://www.2ality.com/2014/09/es6-modules-final.html) for bundlers that support the `jsnext:main` or `module` field in package.json (Rollup, Webpack 2) The `animate-value` package includes precompiled production and development [UMD](https://github.com/umdjs/umd) builds in the [`dist` folder](https://unpkg.com/animate-value/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a [`<script>` tag](https://unpkg.com/animate-value) on your page. The UMD builds make `animate-value` available as a `window.animateValue` global variable. ### Usage ### setup ```js import av from 'animate-value'; av({ from: 0, to: 10, duration: 2000, change: value => console.log(value) }); ``` ### configuration You can pass in extra options as a configuration object (āž• required, āž– optional, āœļø default). ```js import av from 'animate-value'; av({ from: 0, to: 20, easing: 'linear', duration: 1000, delay: 1000, loopDelay: 500, loop: true, reverse: true }); ``` āž– **from** ( Number ) ` āœļø 0 ` <br/> šŸ“ start value āž– **to** ( Number ) ` āœļø 1 ` <br/> šŸ“ end value āž– **easing** ( String ) ` āœļø 'easeInQuad' ` <br/> šŸ“ easing function (see below in for more info) āž– **duration** ( Number ) ` āœļø 600 ` <br/> šŸ“ duration (in ms) āž– **delay** ( Number ) ` āœļø 0 ` <br/> šŸ“ delay (in ms) āž– **loop** ( Boolean | Number ) ` āœļø 1 ` <br/> šŸ“ loop the animation, `loop: true` creates an inifinite loop <br/> ā„¹ļø looping with `reverse: true` creates a back- and forwards animation āž– **loopDelay** ( Number ) ` āœļø 0 ` <br/> šŸ“ delay between each loop (back- and forwards in case of `rewind: true`) āž– **rewind** ( Boolean ) ` āœļø false ` <br/> šŸ“ play the animation backwards when finished ### easing You can choose one of these easing functions (default is `easeInOutQuad`) - linear - easeInQuad - easeOutQuad - easeInOutQuad - easeInCubic - easeOutCubic - easeInOutCubic - easeInQuart - easeOutQuart - easeInOutQuart - easeInQuint - easeOutQuint - easeInOutQuint based on [https://gist.github.com/gre/1650294#gistcomment-1806616](https://gist.github.com/gre/1650294#gistcomment-1806616) <br/>all credit to [@lindell](https://github.com/lindell) ### events #### change šŸ“ triggered on each change of the value, passes the value as parameter ```js import av from 'animate-value'; av({ from: 0, to: 20, duration: 2000, loop: true change: value => console.log(value) }); ``` #### done šŸ“ triggered at the end of the 'animation' <br/>ā—ļø never triggered when `loop: true` ```js import av from 'animate-value'; av({ from: 0, to: 10, duration: 1500, done: () => console.log('done') }); ``` You can also use the Promise provided on `animate-value` ```js import av from 'animate-value'; av({ from: 0, to: 10, duration: 2000 }).then(() => console.log('done')); ``` ### Examples See [`example`](example). ### License The code is available under the [MIT](LICENSE) license. ### Contributing We are open to contributions, see [CONTRIBUTING.md](CONTRIBUTING.md) for more info. ### Misc This module was created using [generator-module-boilerplate](https://github.com/duivvv/generator-module-boilerplate).