Javascript stopwatch

Developer
Size
2,102 Kb
Views
16,192

How do I make an javascript stopwatch?

What is a javascript stopwatch? How do you make a javascript stopwatch? This script and codes were developed by Dave DeHaan on 04 January 2023, Wednesday.

Javascript stopwatch Previews

Javascript stopwatch - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>javascript stopwatch</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <center>
<div id="stopwatch"> <span id="minute">00</span><span id="second">00</span><span id="ms">00</span> <br /> <button id="start" onclick="start();">start</button> <button id="stop" onclick="stop();">stop</button>
</div>
</center> <script src="js/index.js"></script>
</body>
</html>

Javascript stopwatch - Script Codes CSS Codes

body { font-family: arial;
}
#stopwatch { width: 200px; height: 100px; background: #CCC; color: #333; border: solid 2px #333; border-radius: 150px; padding: 60px 50px 100px; text-align: center; font-size: 30px;
}
#stopwatch span { background: #fff; padding: 3px; border-radius: 5px; border: solid 2px #333; margin: 3px; display: inline-block;
}
#stopwatch button:first-of-type { margin-top: 25px;
}
#stopwatch button { font-size: 20px; -webkit-appearance: none; border: solid 2px #333; background: #fff; color: #333; border-radius: 5px; width: 100px; margin-top: 5px; transition: .3s;
}
#stopwatch button:hover { border: solid 2px #fff; background: #333; color: #fff; cursor: pointer;
}

Javascript stopwatch - Script Codes JS Codes

var timer = 0;
var timerInterval;
var ms = document.getElementById('ms');
var second = document.getElementById('second');
var minute = document.getElementById('minute');
function start() { stop(); timerInterval = setInterval(function() { timer += 1/60; msVal = Math.floor((timer - Math.floor(timer))*100); secondVal = Math.floor(timer) - Math.floor(timer/60) * 60; minuteVal = Math.floor(timer/60); ms.innerHTML = msVal < 10 ? "0" + msVal.toString() : msVal; second.innerHTML = secondVal < 10 ? "0" + secondVal.toString() : secondVal; minute.innerHTML = minuteVal < 10 ? "0" + minuteVal.toString() : minuteVal; }, 1000/60);
}
function stop() { clearInterval(timerInterval);
}
Javascript stopwatch - Script Codes
Javascript stopwatch - Script Codes
Home Page Home
Developer Dave DeHaan
Username davedehaan
Uploaded January 04, 2023
Rating 3
Size 2,102 Kb
Views 16,192
Do you need developer help for Javascript stopwatch?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Dave DeHaan (davedehaan) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!