accurate-timer
Advanced tools
Comparing version 0.0.3 to 0.0.4
(function(root){ | ||
var Timer = root.Timer = function(callback, interval){ | ||
if (window) { | ||
var Timer = function(callback, interval){ | ||
this.raf = window.requestAnimationFrame | ||
|| window.mozRequestAnimationFrame | ||
|| window.webkitRequestAnimationFrame | ||
|| window.msRequestAnimationFrame; | ||
if (this.raf) { | ||
this.type = 'requestAnimationFrame'; | ||
this.raf = window.requestAnimationFrame | ||
|| window.mozRequestAnimationFrame | ||
|| window.webkitRequestAnimationFrame | ||
|| window.msRequestAnimationFrame; | ||
} else { | ||
@@ -20,2 +21,3 @@ this.type = 'setInterval'; | ||
Timer.prototype.start = function(){ | ||
this.stop(); | ||
var that = this; | ||
@@ -25,5 +27,7 @@ | ||
case 'requestAnimationFrame': | ||
console.log('using raf') | ||
that._startRAF(); | ||
break; | ||
case 'setInterval': | ||
console.log('using SI') | ||
that._startSI(); | ||
@@ -78,4 +82,2 @@ break; | ||
})(this); | ||
window.t = new this.Timer(function(time){console.log(time)}, 1000) | ||
})(this); |
{ | ||
"name": "accurate-timer", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "An accurate timer using requestAnimationFrame() and performance.now(), defaulting to setInterval when needed.", | ||
@@ -5,0 +5,0 @@ "main": "accurate_timer.js", |
@@ -1,11 +0,18 @@ | ||
### An accurate, multienvironment timer | ||
# accurate_timer uses requestAnimationFrame() and performance.now(), defaulting to setInterval if it's used in a non-browser environment. | ||
# An accurate, multienvironment timer | ||
##### accurate_timer uses requestAnimationFrame() and performance.now(), defaulting to setInterval if it's used in a non-browser or older environment. | ||
## Supported environments | ||
* Node.js (All major versions) | ||
* Chrome* | ||
* Firefox* | ||
* IE* | ||
* Must have requestAnimationFrame supported. Vendor prefixed is OK. | ||
Based on my own (unscientific) measurements, the timer in a node.js environment tends to be accurate to about 3/1000ths of a second. In a browser environment it's a little less than 1/1000ths of a second. | ||
Based on my own (unscientific) measurements, the timer in a node.js environment tends to be accurate to about 3/1000ths of a second. In a browser environment it's a little less than 1/1000ths of a second. | ||
## Usage | ||
* Create a timer object: | ||
```js | ||
var timer = new Timer(<callback>, <interval>); | ||
``` | ||
* start / stop the timer: | ||
```js | ||
timer.start(); | ||
timer.stop(); | ||
``` | ||
All done! I hope you enjoy :blush: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3261
63
18