Timaline is a requestAnimationFrame based tasks scheduler.
- Reduce RAF Delta impact by "prev or next" frame
- Speed
- Repeat
- User custom loop (manually update)
- Disable RAF when web page is not active
- Playback control
- RAF Delta impact reducing by average calculation
- Reduce RAF Delta aftereffect
- Set callback functions
- Wait time in millisecond
- AddClass to a node
- RemoveClass to a node
- Destroy everything
- Control speed
- Control repeat
- Update manually
- Pause when tab is not visible
IE 10+
var Timaline = require('Timaline');
You can pass 3 options to constructor, and you can combine them :
var timeline = new Timaline({
loop: false, // default : true
speed: 0.5, // default : 1
repeat: 3 // default : 0
});
Wait time.
Time to wait in millisecond
Call your function.
The fonction you need to call
AddClass shortcut.
Your dom element
Your class name
RemoveClass shortcut.
Your dom element
Your class name
Roughly destroy your timeline.
Speed will control entire timeline (default: 1)
Repeat your timeline as many times as you like (default: 0)
When you set a callback, infos are available :
var delay = new Timaline();
delay
.wait(200)
.set(function(infos){
console.log(infos);
});
var infos = {
index: 2, // The index of your task
keyframe: {
forecast: 3000, // Time forecast by set wait time
real: 2996, // Real time (with RAF Delta)
shift: -4 // Shift between both
}
};
This example is a simple delayed task, similar as a simple window.setTimeout :
var delay = new Timaline();
delay
.wait(200)
.set(function(infos){
console.log(infos);
});
This example is a chained tasks :
var timeline = new Timaline();
timeline
.wait(1000)
.set(function(infos){
console.log('task index :' + infos.index );
})
.wait(2000)
.set(function(infos){
console.log('task index :' + infos.index );
});
If you need, you can use shortcuts methods during your timeline : (consider that the used classes exist in your stylesheet)
var $header = document.getElementById('header');
var $container = document.getElementById('container');
var $footer = document.getElementById('footer');
var hidePage = new Timaline();
hidePage
.set(function(infos){
console.log('This page will disappear in a while.');
})
.wait(1000)
.addClass($header, 'fadeOut')
.wait(800)
.removeClass($container, 'shown')
.wait(1000)
.addClass($footer, 'scaleOut')
.set(function(infos){
console.log('That\'s all folks!');
});
This example show how to update Timaline with your own loop :
var delay = new Timaline({
raf: false
});
function loop( timestamp ) {
delay.update( timestamp );
requestAnimationFrame( loop );
}
requestAnimationFrame( loop );
delay
.wait(200)
.set(function(infos){
console.log(infos);
});
A timeline is destructs when it is finished, but sometimes you need to roughly destroy it before the end :
// Create a new timeline
var timeline = new Timaline();
timeline
.wait(3000)
.set(function(infos){
console.log('I\'ll never be call.');
})
.wait(1000)
.set(function(infos){
console.log('me too.');
});
// ..and create a new one that will remove
// the first one before its end
var destroy = new Timaline();
destroy
.wait(1000)
.set(function(infos){
timeline.destroy();
});