animore
Animore makes DOM state transitions easier
It uses internally the css transitions to animate 2 different states of the same DOM node. It was inspired by riot-animore and works thanks to the flip technique by Paul Lewis
Demos
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 transitions
You can pass a query or a DOM node to animore
in the following way:
const animaQuery = animore('.my-div')[0]
const animaNode = animore(myDiv)[0]
const animaList = animore([myDiv, myUl])
const animaNodeList = animore(myUl.children)
Remeber to use stash
and apply
to create your transitions
const anima = animore('.my-div')[0]
anima.stash()
anima.el.style.marginTop = '300px'
anima.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 call will return an object with the following properties
animore.stash
Store the current DOM node position and size
@returns self
animore.apply
Apply the transition comparing the current DOM node state with its previous state (it can be called only after a stash
)
@returns self
animore.el
Reference to the DOM node queried
@returns HTMLElement