Build a precise stopwatch with lap timing functionality and split tracking
Create a professional stopwatch application with lap timing capabilities. Perfect for tracking workouts, races, or any timed activities with multiple checkpoints.
To get started, you can use the following code snippet to implement timing:
let startTime = null;
let elapsedTime = 0;
let laps = [];
let animationFrameId = null;
function start() {
startTime = performance.now() - elapsedTime;
update();
}
function update() {
elapsedTime = performance.now() - startTime;
displayTime(elapsedTime);
animationFrameId = requestAnimationFrame(update);
}
function recordLap() {
laps.push({
lapNumber: laps.length + 1,
time: elapsedTime,
lapTime: laps.length > 0 ? elapsedTime - laps[laps.length - 1].time : elapsedTime
});
displayLaps();
}