progress-timer
v0.1.0
Published
An event base progress timer with start,pause,reset
Downloads
2
Readme
Progress Timer
An event base accurate timer with start,pause,reset
Quick Example
- clone or download the project
- cd examples
- open examples in browser
or edit on jsfiddle
Install
ProgressTimer is an UMD module, so you can
<script src="../progress-timer.js"></script>
or do this
require('progress-timer')
Basic Usage
var timer = new ProgressTimer({
total: 3000 // total time,the unit is ms,default to Infinity
})
timer.on('change', function (currentTime, timer) {
// do something
})
timer.start()
Documentation
options
- total - Defaults to Infinity, total execute time
- interval - Defaults to 1000 / 60 for 60 fps, execute interval
methods
- start(time) - start or continue timer
- time(optional) - Start timer from
time
. If notime
provided, timer will start from 0(zero) or continue from last pause time
- time(optional) - Start timer from
- pause() - Pause timer
- stop() - Stop timer
- reset() - Same as
stop
, only an alias method - current(time) - Get current time in ms or change current time
- time(optional) - Get current time if
time
not provided .Or set current time iftime
provided
- time(optional) - Get current time if
- currentProgress() - Get current progress in percent( same as
timer.current() / timer.total
) - state() - Get current state (init | started | pause | completed)
- on(event, callback)
- event(string) - change | start | pause | reset | completed | seek
- callback(function) - Callback for spec event
License
MIT