-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a19f1e
Showing
3 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Stopwatch</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div id="stopwatch"> | ||
<h1>Click to start and click to stop</h1> | ||
|
||
<div id="curTime">0</div> | ||
<div id="display"></div> | ||
|
||
<div class="button-group"> | ||
<button id="start" type="button" aria-label="Start">Start</button> | ||
<button id="stop" type="button" aria-label="Stop">Stop</button> | ||
<button id="reset" type="button" aria-label="Reset">Reset</button> | ||
<button id="lapse" type="button" aria-label="Lapse">Lapse</button> | ||
<button id="pause" type="button" aria-label="Pause">Pause</button> | ||
<button id="continue" type="button" aria-label="Continue">Continue</button> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var cur; | ||
let ftime; | ||
let interval; | ||
let isPaused = false; | ||
let pausedTime = 0 | ||
|
||
const dif = function(){ | ||
ftime = Date.now(); | ||
|
||
document.getElementById('curTime').innerHTML = (( ftime - cur) + pausedTime)/1000; | ||
} | ||
|
||
document.getElementById('start').addEventListener('click', function(){ | ||
cur = Date.now(); | ||
interval = setInterval(dif, 1000); | ||
|
||
}); | ||
|
||
document.getElementById('stop').addEventListener('click', function(){ | ||
clearInterval(interval); | ||
}); | ||
document.getElementById('reset').addEventListener('click', function(){ | ||
clearInterval(interval); | ||
document.getElementById('curTime').innerHTML = 0; | ||
document.getElementById('display').innerHTML = ""; | ||
pausedTime = 0; | ||
isPaused = false; | ||
|
||
|
||
}); | ||
document.getElementById('lapse').addEventListener('click', function(){ | ||
if (!isPaused){ | ||
const element1 = document.createElement('div'); | ||
element1.innerHTML = (Date.now() - cur) / 1000; | ||
document.getElementById('display').appendChild(element1); | ||
} | ||
|
||
}); | ||
|
||
document.getElementById('pause').addEventListener('click', function(){ | ||
if (!isPaused){ | ||
clearInterval(interval); | ||
pausedTime = Date.now() - cur; | ||
isPaused = true; | ||
} | ||
}) | ||
|
||
document.getElementById('continue').addEventListener('click', function(){ | ||
if (isPaused){ | ||
cur = Date.now() - pausedTime; | ||
interval = setInterval(dif,1000); | ||
isPaused = false; | ||
pausedTime = 0; | ||
} | ||
}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f0f0f0; | ||
margin: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
#stopwatch { | ||
background-color: #fff; | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); | ||
text-align: center; | ||
width: 90%; | ||
max-width: 600px; | ||
} | ||
|
||
h1 { | ||
color: #333; | ||
} | ||
|
||
#curTime { | ||
font-size: 48px; | ||
margin: 20px 0; | ||
color: #4CAF50; | ||
} | ||
|
||
#display { | ||
margin-top: 20px; | ||
} | ||
|
||
#display div { | ||
background-color: #2196F3; | ||
color: white; | ||
padding: 10px; | ||
margin-bottom: 5px; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.button-group { | ||
display: flex; | ||
justify-content: center; | ||
flex-wrap: wrap; | ||
} | ||
|
||
button { | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
padding: 10px 20px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
margin: 5px; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
button:hover { | ||
background-color: #45a049; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
#stopwatch { | ||
padding: 10px; | ||
} | ||
|
||
#curTime { | ||
font-size: 36px; | ||
} | ||
|
||
.button-group { | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
} | ||
} |