transform-js
v1.1.0-final.1512141547
Published
Simple transformations with start/stop/pause/resume/cancel.
Downloads
33
Maintainers
Readme
transform.js
Simple JavaScript transformations, e.g. for tweening, that can be paused, resumed and canceled.
Installation
npm install transform-js
Usage
var t = transformation(from, to, update, options, after);
t
: An object with methods to control the transformation.from
: The start value.to
: The end value.update
: A function that receives the current value of the transformation.options
: An object to configure the transformation (optional):duration
: Duration for the transformation.easing
: An easing function or name of an easing function from node packageeases
.fps
: Frames per second to use.
after
: Callback for when the transformation has stopped or is canceled (optional).
var transformation = require("transform-js").transformation;
var t = transformation(0, 1000, update);
function update (newValue) {
// ...
console.log(newValue);
}
t.start();
Canceling
You can cancel a transformation:
t.cancel();
Canceling stops the transformation. The last value will be the current value of the transformation.
Stopping
You can stop a running transformation:
t.stop();
The last value will be the to
value of the transformation.
Pause/resume
A transformation can be paused and resumed:
t.start();
setTimeout(function () {
t.pause();
}, 500);
setTimeout(function () {
t.resume();
}, 1000);