Stopwatch.js is a JavaScript-based stopwatch library.
Lightweight, easy to use,
Available in browsers, ESM, CJS, AMD, and UMD.
Note
: Please enter a value of {version} in the import path.
<script type="javascript" src="https://cdn.jsdelivr.net/npm/@zzinpan/stopwatch.js@{version}/dist/iife/Stopwatch.min.js"></script>
<script type="module">
import Stopwatch from "https://cdn.jsdelivr.net/npm/@zzinpan/stopwatch.js@{version}/dist/esm/Stopwatch.min.js";
// ...
</script>
# Installation
npm install @zzinpan/stopwatch.js
const Stopwatch = require( "@zzinpan/stopwatch.js" );
// ...
import Stopwatch from "Stopwatch.js";
// create api
const stopwatch = new Stopwatch();
// add events
stopwatch.on( "update", ( time ) => console.log( time ) );
stopwatch.on( "alarm", ( time ) => alert( time ) );
// set alarm
stopwatch.setAlarm( 5000, Stopwatch.AlarmType.ABSOLUTE );
// start
stopwatch.start();
The same features are implemented in IIFE, ESM, AMD, and UMD respectively.
- start: click the right button
- stop: click the right button ( toggle )
- pause: click the left button ( during the start )
- setAlarm: drag the small hand
- stopAlarm: click the stopwatch
https://zzinpan.github.io/Stopwatch.js/sample/index.html
https://zzinpan.github.io/Stopwatch.js/sample/index-esm.html
https://zzinpan.github.io/Stopwatch.js/sample/index-amd.html
https://zzinpan.github.io/Stopwatch.js/sample/index-umd.html
If you want to use a simple stopwatch:
https://zzinpan.github.io/Stopwatch.js/docs/classes/Stopwatch.default.html
If you want to create a custom AlarmType:
https://zzinpan.github.io/Stopwatch.js/docs/classes/Stopwatch_AlarmType.default.html
If you are curious about the full code:
https://zzinpan.github.io/Stopwatch.js/docs/
If you want to see a test coverage:
https://zzinpan.github.io/Stopwatch.js/coverage/lcov-report/index.html
Thanks for using it!