Advertisement
Guest User

Untitled

a guest
May 29th, 2016
2,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. body {
  6. background-color: #e6e6e6;
  7. }
  8. h1 {
  9. font-size: 4.5em;
  10. }
  11.  
  12. button {
  13. font-size: 30px;
  14. width: 140px;
  15. height: 60px;
  16. border-radius: 5px;
  17. }
  18.  
  19. #startPause {
  20. background-color: green;
  21. border-color: green;
  22. }
  23.  
  24. #reset {
  25. background-color: gray;
  26. border-color: gray;
  27. }
  28.  
  29. .container {
  30. margin: auto;
  31. margin-top: 200px;
  32. width: 400px;
  33. height: 400px;
  34. }
  35. #controls {
  36. margin-left: 7px;
  37. width: 310px;
  38. height:70px;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <script>
  44. var time = 0;
  45. var running = 0;
  46. function startPause(){
  47. if(running == 0){
  48. running = 1;
  49. increment();
  50. document.getElementById("start").innerHTML = "Pause";
  51. document.getElementById("startPause").style.backgroundColor = "red";
  52. document.getElementById("startPause").style.borderColor = "red";
  53. }
  54. else{
  55. running = 0;
  56. document.getElementById("start").innerHTML = "Resume";
  57. document.getElementById("startPause").style.backgroundColor = "green";
  58. document.getElementById("startPause").style.borderColor = "green";
  59. }
  60. }
  61. function reset(){
  62. running = 0;
  63. time = 0;
  64. document.getElementById("start").innerHTML = "Start";
  65. document.getElementById("output").innerHTML = "0:00:00:00";
  66. document.getElementById("startPause").style.backgroundColor = "green";
  67. document.getElementById("startPause").style.borderColor = "green";
  68. }
  69. function increment(){
  70. if(running == 1){
  71. setTimeout(function(){
  72. time++;
  73. var mins = Math.floor(time/10/60);
  74. var secs = Math.floor(time/10 % 60);
  75. var hours = Math.floor(time/10/60/60);
  76. var tenths = time % 10;
  77. if(mins < 10){
  78. mins = "0" + mins;
  79. }
  80. if(secs < 10){
  81. secs = "0" + secs;
  82. }
  83. document.getElementById("output").innerHTML = hours + ":" + mins + ":" + secs + ":" + tenths + "0";
  84. increment();
  85. },100)
  86. }
  87. }
  88. </script>
  89. <div class="container">
  90. <h1><p id="output"><b>0:00:00:00</b></p></h1>
  91. <div id="controls" align="center">
  92. <button id= "startPause" onclick="startPause()"><b id="start">Start</b></button>
  93. <button onclick="reset()" id="reset"><b id="reset">Reset</b></button>
  94. </div>
  95. </div>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement