vq
A light-weight and functional animation helper for Velocity.js
Dependencies
vq requires Velocity.js. You have to load Velocity.js before using vq.
Installation
$ npm install vq
or download from release page.
Demo
Example
/* Animation behaviors----------------------------------------*/var fadeIn = p: opacity: 1 0 o: duration: 500 easing: 'easeOutQuad' ; var fadeOut = p: opacity: 0 1 o: duration: 500 easing: 'easeInQuad' ; /* Animation elements----------------------------------------*/var $foo = ;var $bar = ; /* Animation sequence----------------------------------------*/var seq = vq; ;
API
vq provides global function vq(el, props, opts)
, vq.sequence(funcs)
and vq.parallel(funcs)
.
vq(el, props, opts)
This function returns a function that executes animation by given element, property and options.
var el = document;var func = ; // generate a function; // <-- The animation is executed on this time
You can combine the props
and opts
to Velocity-like single object.
var fadeIn = p: opacity: 1 0 o: duration: 500 ; var func = ;;
You can pass a Velocity's progress callback to the 2nd argument or the value of p
.
var swing = { var offset = 100 * Math; el0styletransform = 'translate3d(' + offset + 'px, 0, 0)'; } o: duration: 1000 easing: 'easeOutCubic' var func = ;;
The function receives 1st argument as completion callback. You can handle the animation completion from the callback;
var func = ;;
vq.sequence(funcs)
This function receives the array of functions and returns a function to execute them sequentially. If the given function returns Promise object or has callback function as 1st argument, vq.sequence waits until the asynchronous processes are finished.
var seq = vq; ;// The output order is 1 -> 2 -> 3
The function is useful with using vq(el, props, opts)
.
var animSeq = vq;
vq.parallel(funcs)
This function is same as vq.sequence
except to execute in parallel.
var para = vq; ;// The output order may be 3 -> 2 -> 1
vq.stop(els)
This function creates animation stopper for given elements. If you execute returned function, all animated elements is stopped.
var stopFn = vq; var seq = vq; ; // stop `seq` animations after 3000msec
Event helpers
DOM Event helpers
vq can handle DOM events by event helpers and execute some animation after receiving the events.
vq has following event helpers.
- click
- dblclick
- mousedown
- mouseup
- mousemove
- mouseenter
- mouseleave
- focus
- blur
- change
- input
- scroll
- load
The helper functions expect a DOM element for the argument and returns a new function.
The returned function expect an animation function that you will get from vq
, vq.sequence
or vq.parallel
functions.
var click = vq; var fade = vq; ;
You can create a new event helper by using vq.element
function.
vq.element
receives an element, a DOM event name and an optional filter function.
If you specify the filter function, your event helper does not execute an animation function until the filter function returns true
.
var helloWorld = vq; var seq = vq; ;
Delay Helper
vq.delay(msec)
returns the function that delays given callback for msec
.
This function can use for not only animation function but also normal functions.
var delay1s = vq; var delayedFn = ; ;
vq chainable helper methods
The function returned by vq(el, props, opts)
has some chainable helper methods. The helpers can modify animation options and behaviors.
vq;
.delay(msec)
Set the delay of animation start to msec
.
.duration(msec)
Set the duration of animation to msec
.
.easing(name)
Set the easing of animation to name
. name
should be easing function name that allowed on Velocity.js.
.progress(func, tween)
Set the progress function to func
.
tween
is optional argument and it is set to props.tween
. [1, 0]
is set if tween
is omitted and props.tween
is not set previously.
See Velocity.js documentation to learn tween property.
.display(value)
Set the display option to value
.
.visibility(value)
Set the visibility option to value
.
.loop(count)
Set the loop option to count
.
.stagger(msec)
Set the delay between each element animation to msec
.
Contribution
Contribution is welcome! Feel free to open an issue or a pull request.
License
MIT