1.0.17 • Published 6 years ago
project-simple-red-timer v1.0.17
RedTimer
Simple Javascript Timer
github - here
Install
npm
npm install project-simple-red-timer --save-devimport RedTimer from 'project-simple-red-timer';browser
<script src="https://project-simple.github.io/RedTimer/dist/RedTimer.min.js"></script>
<script>
RedTimer(
'testKey_1',
1000,
function(){},
function(){}
);
</script>API
RedTimer(key, duration, updateCallback, endCallback)
| param | description | type |
|---|---|---|
key | unique key | string |
duration | timer duration | positive number(Millisecond) |
updateCallback | Register a function to be called whenever the timer is updated. | function or undefined |
endCallback | Register a function to be called when the timer is end. | function or undefined |
var t0 = RedTimer('testKey_1',1000,function(){}, function(){});
var t1 = new RedTimer('testKey_2',1000,function(){}, function(){});
console.log(t0 instanceof RedTimer); // true
console.log(t1 instanceof RedTimer); // auto call constructorproperty
| name | description | read/write | type |
|---|---|---|---|
key | Timer key | read-only | string |
duration | Timer duration | read/write | positive number(Millisecond) |
startTime | Timer startTime | read-only | number(Millisecond) |
endTime | Timer endTime | read-only | number(Millisecond) |
elapsedTime | Timer elapsedTime | read-only | number(Millisecond) |
remainTime | Timer remainTime | read-only | number(Millisecond) |
RedTimer(
'testKey_1',
1000,
function(){
console.log('key', this.key);
console.log('duration', this.duration);
console.log('startTime', this.startTime);
console.log('endTime', this.endTime);
console.log('elapsedTime', this.elapsedTime);
console.log('remainTime', this.remainTime);
console.log('//////////////////////')
},
function(){}
);method
(RedTimer Instance).destroy()
var t0 = RedTimer('testDestroy',1000,function(){},function(){})
t0.destroy();- Target timer destroyed immediately (endCallback not called)
static method
RedTimer.destroyAll()
RedTimer( 'testDestroyAll_1', 1000, function(){}, function(){} );
RedTimer( 'testDestroyAll_2', 2000, function(){}, function(){} );
RedTimer( 'testDestroyAll_3', 3000, function(){}, function(){} );
RedTimer( 'testDestroyAll_4', 4000, function(){}, function(){} );
RedTimer.destroyAll();- Destroys the currently active RedTimer instance. (endCallback not called)
