animato
Simple way to animate anything (even simple values).
:cloud: Installation
npm install --save animato
yarn add animato
:clipboard: Example
var Animato = require("animato");
Animato({
x: -3
, y: -6
}).to({
x: 2
, y: 4
}).duration(1000).step(function (c) {
console.log(c);
}).start(function () {
console.log("complete");
});
Animato({
from: {
x: 0
, y: 5
}
, to: {
x: 10
, y: 10
}
, duration: 100
, step: function (c) {
console.log(c);
}
, complete: function (c) {
console.log("complete");
}
});
var frames = Animato.Frames({
x: -10
, y: 2
}, {
x: 10
, y: -3
}, 20);
console.log(frames.toArray());
frames.step(function (c) {
console.log(c);
}).start(function () {
console.log("Complete.");
});
:question: Get Help
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. :bug:
- For direct and quick help, you can use Codementor. :rocket:
:memo: Documentation
Animato(from, to, time, step, complete)
Creates a new Animato
instance.
Usage:
Animato({...}).to({...}).duration(1000).step(function (c) {
...
}).start(function () {
...
});
Animato({
from: {...}
, to: {...}
, duration: 1000
, step: function () {...}
, complete: function () {...}
})
Params
- Object
from
: The source object. - Object
to
: The target object. - Number
time
: The animation duration (milliseconds). - Function
step
: The step function. - Function
complete
: The complete function.
Return
- Animato The
Animato
instance.
to(to)
Sets the target object.
Params
- Object
to
: The target object.
Return
- Animato The
Animato
instance.
duration(duration)
Sets the animation duration.
Params
- Number
duration
: The animation duration (milliseconds).
Return
- Animato The
Animato
instance.
step(fn)
Sets the step function. This function will be called every time when the animation changes.
Params
- Function
fn
: The step function.
Return
- Animato The
Animato
instance.
complete(fn)
Sets the complete function. This function will be called when the animation is done.
Params
- Function
fn
: The complete function.
Return
- Animato The
Animato
instance.
start(fn)
Starts the animation.
Params
- Function
fn
: The complete function.
Return
Frames(from, to, count)
Generate frames for two given objects (source and target).
Params
- Object
from
: The source object. - Object
to
: The target object. - Number
count
: How many frames to generate.
Return
- Frames The
Animato.Frames
instance.
toArray()
Builts the array of frames.
Return
step(fn)
Sets the step function. This function will be called every time when the animation changes.
Params
- Function
fn
: The step function.
Return
- Animato The
Animato
instance.
duration(duration)
Sets the animation duration.
Params
- Number
duration
: The animation duration (milliseconds).
Return
- Animato The
Animato
instance.
start(fn)
Starts the animation.
TODO This currently uses setInterval because raf
didn't work as expected.
Params
- Function
fn
: The complete function.
Return
:yum: How to contribute
Have an idea? Found a bug? See how to contribute.
:sparkling_heart: Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like :rocket:
-
—I love books! I will remember you after years if you buy me one. :grin: :book:
-
—You can make one-time donations via PayPal. I'll probably buy a coffee tea. :tea:
-
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! :heart:
:scroll: License
MIT © Ionică Bizău