William_Riker

웹 보안 - 타이머 만들기

Oct 27th, 2025
11,259
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.96 KB | None | 0 0
  1. HTML 패널
  2.  
  3. <h2>스톱워치</h2>
  4.  
  5. <div id="display">00:00:00</div>
  6.  
  7. <button id="startBtn">시작</button>
  8. <button id="pauseBtn">일시정지</button>
  9. <button id="resetBtn">리셋</button>
  10.  
  11. JavaScript 패널
  12.  
  13. let seconds = 0;
  14. let minutes = 0;
  15. let hours = 0;
  16. let timer = null;
  17. let isRunning = false;
  18.  
  19. document.getElementById('startBtn').addEventListener('click', function() {
  20.     if (!isRunning) {
  21.         timer = setInterval(updateTimer, 1000);
  22.         isRunning = true;
  23.     }
  24. });
  25.  
  26. document.getElementById('pauseBtn').addEventListener('click', function() {
  27.     clearInterval(timer);
  28.     isRunning = false;
  29. });
  30.  
  31. document.getElementById('resetBtn').addEventListener('click', function() {
  32.     clearInterval(timer);
  33.     isRunning = false;
  34.     seconds = 0;
  35.     minutes = 0;
  36.     hours = 0;
  37.     updateDisplay();
  38. });
  39.  
  40. function updateTimer() {
  41.     seconds++;
  42.    
  43.     if (seconds >= 60) {
  44.         seconds = 0;
  45.         minutes++;
  46.     }
  47.    
  48.     if (minutes >= 60) {
  49.         minutes = 0;
  50.         hours++;
  51.     }
  52.    
  53.     updateDisplay();
  54. }
  55.  
  56. function updateDisplay() {
  57.     let h = hours < 10 ? '0' + hours : hours;
  58.    let m = minutes < 10 ? '0' + minutes : minutes;
  59.    let s = seconds < 10 ? '0' + seconds : seconds;
  60.    
  61.    document.getElementById('display').textContent = h + ':' + m + ':' + s;
  62. }
  63.  
  64. CSS 패널
  65.  
  66. body {
  67.    font-family: 'Courier New', monospace;
  68.    text-align: center;
  69.    padding: 50px;
  70.    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  71.    color: white;
  72. }
  73.  
  74. #display {
  75.    font-size: 72px;
  76.    margin: 30px 0;
  77.    padding: 20px;
  78.    background-color: rgba(0, 0, 0, 0.3);
  79.    border-radius: 10px;
  80.    display: inline-block;
  81. }
  82.  
  83. button {
  84.    padding: 15px 30px;
  85.    margin: 10px;
  86.    font-size: 18px;
  87.    cursor: pointer;
  88.    border: none;
  89.    border-radius: 5px;
  90.    background-color: white;
  91.    color: #667eea;
  92.    font-weight: bold;
  93. }
  94.  
  95. button:hover {
  96.    background-color: #f0f0f0;
  97. }
Advertisement