Core Docs | Additional Modules Docs
@Description: A constructor to create a timer, which is an event firing timer that repeats on an increment
@File: utils/timer.js
@Param: Object o
handler - the function to fire after the delay
seconds - the number of seconds to wait before firing
milliseconds - the number of milliseconds to wait before firing
@Example://create a new timer
var myTimer = new sb.utils.timer({
//set the number of seconds between intervals - alternatively you can set the number of milliseconds
seconds : 0.01,
//set the function that will fire reapeatedly on interval
handler : function(){
//reference the this.count property of the time to make sure it has fired less than 255 times
if(this.count <255){
//set the document title to the count for debugging
document.title = this.count;
//set the background color of the body to incremement with the count
document.body.style.backgroundColor = 'rgb('+this.count+',2,3)';
} else {
//it has fired 255 times, end the timer
this.end();
}
}
});
//start the timer;
myTimer.begin();
@Description: These properties are avaiable to any sb.utils.timer instance. All sb.utils.timer.prototype examples below assume a timer name myTimer was instantiated previously in the code
@File: utils/timer.js
@Example://creates a timer which changes the document's title to the current date every 2 seconds
var myTimer = new sb.utils.timer({
handler: function(){
document.title = new Date();
},
seconds : 2
});
@Description: begins the repeat event firing based on the interval specified for a sb.utils.timer instance, if an onbegin property was set than it fires on first firing
@File: utils/timer.js
@Example:myTimer.begin();
@Description: ends the repeat event firing, if an onbegin property was set than it fires on first firing
@File: utils/timer.js
@Param: Boolean resetCount Optional argument. If set the timer instance's counter is reset. I would suggest just calling myTimer.reset which ends the timer and resets automatically.
@Example:myTimer.end();
@Description: ends the repeat event firing and resets the count property on a sb.utils.timer instance
@File: utils/timer.js
@Example:myTimer.reset();
@Description: ends the repeat event firing and resets the count property and starts it again for an sb.utils.timer instance.
@File: utils/timer.js
@Example:myTimer.changeInterval({seconds :10});
@Description: ends the repeat event firing and resets the count property and starts the timer again for an sb.utils.timer instance
@File: utils/timer.js
@Example:myTimer.restart();