Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made stopwatch from HTML,CSS & JS #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stopwatch -using Javascript</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="stopwatch">
<h1 id="displayItem">00:00:00</h1>
<div class="buttons">
<img src="stop_white_button_icon_227857-removebg-preview.png" alt="" onclick="watchStop()">
<img class="start" src="white-play-button-icon-on-transparent-background-flat-style-white-play-button-icon-for-your-web-site-design-logo-app-ui-play-symbol-2M0MWX5-removebg-preview.png" alt="" onclick="watchStart()">
<img src="pngtree-refresh-ccw-flat-white-color-icon-ccw-rotate-reset-vector-png-image_19938782-removebg-preview.png" alt="" onclick="watchReset()">
</div>
</div>


<script src="script.js"></script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

let [seconds,minutes,hours] = [0,0,0];
let displayItem = document.getElementById("displayItem");
let timer = null;

function stopwatch() {
seconds++;
if (seconds == 60) {
seconds = 0;
minutes++;
if (minutes == 60) {
minutes = 0;
hours++;
}
}

let h = hours < 10 ? "0" + hours :hours;
let m = minutes < 10 ? "0" + minutes : minutes;
let s = seconds < 10 ? "0" + seconds : seconds


displayItem.innerHTML = h+ ":" + m + ":" + s;
}
function watchStart() {
if(timer!== null){
clearInterval(timer);
}
timer = setInterval(stopwatch,1000);
}
function watchStop() {
clearInterval(timer);
}
function watchReset() {
clearInterval(timer);
let [seconds,minutes,hours] = [0,0,0];
displayItem.innerHTML = "00:00:00"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
*{
padding: 0;
box-sizing: border-box;
margin: 0;
}
body{
background: #222;
color: white;
}
.stopwatch{
width: 90%;
max-width: 600px;
background-color: #323741;
text-align: center;
padding: 40px 0 ;
color: #fff;
margin: 200px auto 0;
box-shadow: 0 10px 10px rgba(0,0,0,0.8);
}
.stopwatch h1{
margin-top: 60px;
font-size: 64px;
padding: 15px;
margin-top: -1rem;
margin: 35px;
font-weight: 300;
}
.buttons{
display: flex;
align-items: center;
justify-content: center;
}
.buttons .start{
width: 80px;
}
.buttons img {
width: 40px;
margin: 0 20px ;
cursor: pointer;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.