xInterval & xTimeout
Extended Interval and Timeout feature for javascript
Treat new xTimeout() and new xInterval() as a timeline;
You should treat instance of xTimeout and xInterval as timeline, and you specify what action you want to occur in between the time.
xInterval
ForExample;
Syntax:- new xInterval(maxtime);
var timeline=10000;//This timeline has a lenght of 10s timeline
Incase of Interval , by deault in every 100ms , it will look for a action in the timeline, which means you should register you timeline callback in the time which is exactly divisible by 100, i.e 100,200,1100 e.t.c, Any action kept in ms like 1050 (which is multipication of 50 not 100) in timeline will not work. For custom, you can set the clock unit using setClockUnit(unit) method.
var timeline2=new xInterval(10000, 3);
timeline2.setClockUnit(50);
//now you can add action in the multiplication of 50
timeline2.at(1050,function(){});
Also notice we have provide second arguments 3, which means the xnterval will break loop after 3 loops, otherwise it will continue looping unless stop by stop()/clear()/reset() methods.
Controls for xInterval instance
You can use play , pause, resume, forward, backward,reset, stop, and start methods to control the motion on timeline.
var tl=200000;tlstart//to start the motiontl//pause the motiontl//resume the motiontl//stop the motion tl//reset the motiontl// takes 1000ms back from current timetl// forward current time by 300ms
xTimeout [extend setTimeout() features]
Similary, we can use xTimeout(), constructor for timeline. Unlike, xInterval, here we provide action that is invoke in afterward system, for example, Syntax:- new xTimeout(loops);// loops argument is optional
var tl=; tl;//invoke this after 300ms tl;//after preceeding action it will take 300ms to invoke, tl;//after preceeding action it will take 300ms to invoke,
In xTimeout, timeline actions are realtive to each other, it follows FIFO rule. The order in which we register time-action is very important. First it precedeeing action will be invoked,then next action will take place after wating its turn, and so on.
Controls for xTimeout instance
Using play, pause, resume, stop, next, previous, first, last, clear, reset methods, the motion and action on the timline can be effected.
var tl=3;//loop entire procces 3 timestlstart//to start the motiontl//pause the motiontl//resume the motiontl//stop the motion tl//reset the motiontlnext// goto next action settlprevious// back to last actiontl//goto first actiontl//goto last action
Events
You can also trigger a event handler for each control either 'before' ,'after' or 'on' event for control action uisng event object.
beforeplay, onplay,afterplay,onpause,beforepause, onpause, afterpause etc
var tl=10000;tlevent{ //do something //return false to stop the start() method to take place }