Untitled

 avatar
unknown
plain_text
2 years ago
2.8 kB
4
Indexable
<!DOCTYPE html>
<html>
  <head>
    <title>Reloj detallado</title>
    <style>
      body {
        background-color: #eaeaea;
        font-family: sans-serif;
      }

      .container {
        width: 100%;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
      }

      #clock {
        width: 300px;
        height: 300px;
        border-radius: 50%;
        background-color: #f0f0f0;
        border: 2px solid #444;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
      }

      .hour-hand,
      .minute-hand,
      .second-hand {
        position: absolute;
        transform-origin: center;
      }

      .hour-hand {
        width: 50px;
        height: 8px;
        background-color: #444;
        z-index: 3;
      }

      .minute-hand {
        width: 80px;
        height: 6px;
        background-color: #777;
        z-index: 2;
      }

      .second-hand {
        width: 100px;
        height: 4px;
        background-color: #f00;
        z-index: 1;
      }

      .center-dot {
        width: 10px;
        height: 10px;
        background-color: #000;
        border-radius: 50%;
        position: absolute;
        z-index: 4;
      }

      .digital-clock {
        font-size: 48px;
        margin-top: 20px;
        color: #444;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div id="clock">
        <div class="hour-hand"></div>
        <div class="minute-hand"></div>
        <div class="second-hand"></div>
        <div class="center-dot"></div>
      </div>
      <div class="digital-clock"></div>
    </div>

    <script>
      const hourHand = document.querySelector('.hour-hand');
      const minuteHand = document.querySelector('.minute-hand');
      const secondHand = document.querySelector('.second-hand');
      const digitalClock = document.querySelector('.digital-clock');

      function setClock() {
        const now = new Date();
        const seconds = now.getSeconds();
        const minutes = now.getMinutes();
        const hours = now.getHours();

        const secondsDegrees = (seconds / 60) * 360 + 90;
        secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

        const minutesDegrees = (minutes / 60) * 360 + (seconds / 60) * 6 + 90;
        minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;

        const hoursDegrees = (hours / 12) * 360 + (minutes / 60) * 30 + 90;
        hourHand.style.transform = `rotate(${hoursDegrees}deg)`;

        digitalClock.textContent = `${hours
          .toString()
          .padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
      }

      setClock();
      setInterval(setClock, 100
Editor is loading...