Created
May 31, 2017 04:06
-
-
Save whs/214aa84dd051633935cb65add14744f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Clickr</title> | |
| <link rel="stylesheet" href="./style.css"> | |
| </head> | |
| <body> | |
| <div id="title" class="title">Clickr</div> | |
| <div id="message">กดตรงไหนก็ได้เพิ่มเริ่มเล่น</div> | |
| <div id="timer"></div> | |
| <script src="./script.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| let clicks = 0 | |
| let messageBox = document.getElementById('message') | |
| let gameStart = false | |
| let timeStart = 0 | |
| let timeLimit = 5000 | |
| let timer = document.getElementById('timer') | |
| let interval | |
| window.addEventListener('click', onClick) | |
| function onClick() { | |
| clicks++ | |
| messageBox.textContent = clicks | |
| messageBox.style.fontSize = (clicks + 12) + 'pt' | |
| if(!gameStart) { | |
| timeStart = new Date().getTime() | |
| gameStart = true | |
| startTimer() | |
| } | |
| } | |
| function startTimer() { | |
| interval = setInterval(function(){ | |
| let currentTime = new Date().getTime() | |
| let timeDiff = (timeLimit + timeStart) - currentTime | |
| if(timeDiff < 0){ | |
| timeDiff = 0 | |
| clearInterval(interval) | |
| window.removeEventListener('click', onClick) | |
| } | |
| timer.textContent = `เหลือเวลาอยู่ ${(timeDiff/1000).toFixed(1)} sec` | |
| }, 100) | |
| } |
This file contains hidden or 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
| body { | |
| user-select: none; | |
| margin: 0; | |
| } | |
| .title { | |
| text-align: center; | |
| font-size: 48pt; | |
| } | |
| #message { | |
| text-align: center; | |
| } | |
| #timer { | |
| text-align: center; | |
| position: absolute; | |
| bottom: 0; | |
| width: 100%; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment