Advertisement
aupcroft

Need Help manipulating individual buttons in CSS

Jan 19th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Stopwatch deesons practical</title>
  6. <link rel="stylesheet" href="Stopwatch.css">
  7. </head>
  8. <body>
  9.  
  10. <div class="stopwatchBlock">
  11.  
  12. <div class="stopwatch">00:00:00:00</div>
  13. <ul class="laps"></ul>
  14.  
  15.  
  16. <div class="controls">
  17. <button onclick="start()">Start</button>
  18. <button onclick="stop()">Stop</button>
  19. <button onclick="reset()">Reset</button>
  20. <button onclick="lap()">Lap</button>
  21. <button onclick="resetLaps()">Reset Laps</button>
  22.  
  23.  
  24. </div>
  25.  
  26.  
  27. </div>
  28.  
  29. <script src="Stopwatch.js"></script>
  30.  
  31. </body>
  32. </html>
  33.  
  34.  
  35. //css
  36.  
  37. .stopwatchBlock {
  38. width: 500px;
  39. height: 200px;
  40. background-color: #000;
  41. border-radius: 5px;
  42. box-shadow: 0 4px rgba(0, 0, 0, 0.75), 0 0 1px rgba(0, 0, 0, 0.15);
  43. padding: 100px;
  44. }
  45.  
  46. .stopwatchBlock, .stopwatchBlock * {
  47. transition: all 0.15s ease-out;
  48. }
  49.  
  50. .stopwatchBlock .controls {
  51. display: flex;
  52. }
  53.  
  54. .stopwatchBlock .controls button {
  55. flex-grow: 1;
  56. margin: 20px 5px 10px 10px;
  57. padding: 10px 0;
  58. border-radius: 5px;
  59. border: 0;
  60. outline: 0;
  61. font-size: 16px;
  62. color: white;
  63. background-color: orange;
  64. cursor: pointer;
  65. font-weight: bold;
  66. }
  67.  
  68. .stopwatchBlock .controls button:active {
  69. margin-bottom: 0;
  70. margin-top: 4px;
  71. }
  72.  
  73. .stopwatchBlock .controls .start {
  74. background-color: #5d5;
  75. }
  76.  
  77. .stopwatchBlock .controls .start:hover {
  78. background-color: #6e6;
  79. }
  80.  
  81. .stopwatchBlock .controls .stop {
  82. background-color: #d55;
  83. }
  84.  
  85. .stopwatchBlock .controls .stop:hover {
  86. background-color: #e66;
  87. }
  88.  
  89. .stopwatchBlock .controls .reset {
  90. background-color: #55d;
  91. }
  92.  
  93. .stopwatchBlock .controls .reset:hover {
  94. background-color: #66e;
  95. }
  96.  
  97. @font-face {
  98. font-family: 'digital-7';
  99. src: url('digital-7.ttf');
  100. }
  101.  
  102. .stopwatchBlock .stopwatch {
  103. margin-left: 150px;
  104. font-size: 50px;
  105. width: 100px;
  106. color: #fff;
  107. shadow: 0px 0px 5px #fff;
  108. font-family: 'digital-7', sans-serif;
  109. margin-top: 10px;
  110.  
  111. }
  112.  
  113. .stopwatchBlock .stopwatch :not(:last-child):after {
  114. content: ':';
  115. }
  116.  
  117. //JavaScript
  118.  
  119. var ms=0;
  120. var s=0;
  121. var m=0;
  122. var h=0;
  123.  
  124. var timer;
  125.  
  126. var stopwatchElement = document.querySelector('.stopwatch');
  127. var lapsContainer = document.querySelector('.laps');
  128.  
  129.  
  130. function start() {
  131. if (!timer) {
  132. timer = setInterval(run, 10);
  133. }
  134. }
  135.  
  136. function run() {
  137. stopwatchElement.textContent = getTimer();
  138. ms++;
  139. if(ms == 100) {
  140. ms =0;
  141. s++;
  142. }
  143. if (s == 60) {
  144. s = 0;
  145. s++;
  146. }
  147. }
  148.  
  149. function stop() {
  150. start()
  151. stopTimer()
  152. }
  153.  
  154. function stopTimer () {
  155. clearInterval(timer);
  156. timer = false;
  157. }
  158.  
  159. function getTimer() {
  160. return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" +
  161. (s < 10 ? "0" + s : s) + ":" + (ms < 10 ? "0" + ms : ms);
  162. }
  163.  
  164. function reset() {
  165. stopTimer()
  166. ms = 0;
  167. s = 0;
  168. m = 0;
  169. h = 0;
  170. stopwatchElement.textContent = getTimer();
  171. }
  172.  
  173. function lap() {
  174. if(timer) {
  175. var li = document.createElement('li');
  176. li.innerText = getTimer();
  177. lapsContainer.appendChild(li);
  178. }
  179. }
  180.  
  181. function resetLaps() {
  182. lapsContainer.innerHTML = '';
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement