animore
Animore makes DOM state transitions easier
It uses internally the MutationObserver
API to determinate whether a DOM node should be transitioned to a different state. It was inspired by riot-animore and works thanks to the flip technique by Paul Lewis
Installation
Via npm
$ npm i animore -S
Script import
Via <script>
<script src="path/to/animore.js"></script>
Via ES2015 modules
import animore from 'animore'
Via commonjs
const animore = require('animore')
Usage
Simple automatic transitions
You can pass a query or a DOM node to animore
and it will start watching its changes through a MutationObserver
to trigger automatically the transitions.
const anima = animore('.my-div')[0]
anima.el.style.marginTop = '300px'
Manual transitions
You can temporary freeze
the watcher to trigger manually multiple transitions at same time:
const anima = animore('.my-div')[0]
anima.freeze()
anima.el.style.marginTop = '300px'
anima.el.style.marginLeft = '500px'
anima.unfreze().apply()
Options
The animore factory function accepts 2 arguments animore(el, options)
with the options
object you can specify how your animations should behave:
animore(myDiv, {
duration: 300,
easing: 'ease-in-out',
delay: 20,
onStart: function() { console.log('new animation started ')},
onCancel: function() { console.log('animation canceled ')},
onEnd: function() { console.log('animation ended ')}
})
API
Any animore function will return an object with the following properties
animore.destroy
Remove the DOM events disconnecting the MutationObserver internally created
@returns self
animore.apply
Apply manually an animation comparing the current DOM node state with its previous state
@returns self
animore.freeze
Freeze temporarily all the MutationObserver automatic updates
@returns self
animore.unfreeze
Re enable again the automatic transitions updates
@returns self
animore.el
Reference to the DOM node observed
@returns HTMLElement