This time I will share jQuery Plugin and tutorial about Minimal Stopwatch & Timer Plugin For jQuery, hope it will help you in programming stack.
A clean and simple jQuery stopwatch/timer plugin which allows you to count up from zero or a certain time with start, pause and resume controls.
Basic Usage:
1. Create a container for the stopwatch/timer.
1 |
< div id = "t" class = "badge" >00:00</ div > |
2. Create a control button which allows to start, pause and resume the timer in one button.
1 |
< button id = "btn" >Start</ button > |
3. Load the jQuery library and jQuery timer plugin at the end of your page.
1 |
< script src = "/path/to/cdn/jquery.min.js" ></ script > |
2 |
< script src = "/path/to/cdn/timer.jquery.min.js" ></ script > |
4. The JavaScript to enable the timer.
03 |
$( "#btn" ).click( function (){ |
04 |
switch ($( this ).html().toLowerCase()) |
12 |
$( this ).html( "Pause" ); |
13 |
$( "input[name='s']" ).attr( "disabled" , "disabled" ); |
14 |
$( "#t" ).addClass( "badge-important" ); |
18 |
$( "#t" ).timer( 'resume' ); |
20 |
$( "#t" ).addClass( "badge-important" ); |
25 |
$( "#t" ).timer({action: 'pause' }); |
26 |
$( this ).html( "Resume" ) |
27 |
$( "#t" ).removeClass( "badge-important" ); |
5. Style the timer and control button via CSS.
6. Available settings and callbacks
14 |
callback: function () { |
15 |
console.log( 'Time up!' ); |
28 |
updateFrequency: 500 <br> |
7. API methods.
02 |
$( "#div-id" ).timer( 'pause' ); |
05 |
$( "#div-id" ).timer( 'resume' ); |
08 |
$( "#div-id" ).timer( 'remove' ); |
11 |
$( "#div-id" ).data( 'seconds' ); |
8. Get the current state of your timer.
1 |
$('#div-id').data('state'); |
Changelog:
v0.9.1 (2019-12-23)
- Updated timer to support continuous run
v0.9.0 (2018-11-27)
v0.8.0 (2018-09-27)
- Added data state ‘removed
v0.7.0 (2017-04-17)
v0.6.5 (2016-03-23)
v0.6.3 (2016-07-05)
- Fixed redundant early return
v0.6.2 (2016-06-17)
- (fix) Object.assign issue on mobile
- Removed all Object.assign instances
v0.5.3 (2016-06-10)
v0.5.2 (2016-06-08)
- (fix) countdown pause issue
v0.4.14 (2016-05-15)
- Fixed Timer problem Reset
v0.4.10 (2016-01-30)
- Fixed reset timer & added test for reset.
v0.4.9 (2016-01-16)
- Fixed issue where empty args did not translate to start
v0.4.4 (2015-12-27)
- Added AMD support for requirejs
v0.4.3 (2015-08-04)
- FIXED: Pausing, editing the time, and resuming could update the duration to reflect new time
v0.4.2 (2015-06-17)
- Improvement added: Customize timer display update frequency
v0.4.1 (2015-04-25)
- Added functionality to get the current state of the timer.
- Fixed a callback issue when seconds parameter is also passed along with duration parameter
2014-12-07
- Added functionality to edit timer
- Revamped timer.start and added testing ground
2014-11-01
- Switched to nullifying data object from element instead of $.removeData on clearing timer
2014-07-25
- Added repeat callback notification functionality
2014-07-23
- Added function to convert pretty time to seconds
2014-02-19
- Added a check to see if timer is running. Tweaked CSS for demo.
2014-02-06
- added feature to display time in a verbose fashion
- added timer value in seconds to a data attr on the element itself
This awesome jQuery plugin is developed by walmik. For more Advanced Usages, please check the demo page or visit the official website.