martes, 3 de enero de 2023

HTML - Días para Navidad


 Cuenta regresiva para Navidad

Solo lee la letra pequeñita, hay que corregir el código para que se ajusten los dias correctos... Buena practica

HTML

    <div class="sm_counter_cont">
      <div class="sm_santa"></div>
      <h2>! Días para Navidad !</h2>
      <div class="sm_counter_column">
      <div class="sm_column_top" id="xmasdays"></div>
      <div class="sm_column_bottom">Dias</div>
      </div>
      <div class="sm_counter_column">
      <div class="sm_column_top" id="xmashours"></div>
      <div class="sm_column_bottom">Horas</div>
      </div>
      <div class="sm_counter_column">
      <div class="sm_column_top" id="xmasminutes"></div>
      <div class="sm_column_bottom">Minutos</div>
      </div>
      <div class="sm_counter_column">
      <div class="sm_column_top" id="xmasseconds"></div>
      <div class="sm_column_bottom">Segundos</div>
      </div>
      </div>
  </div>

CSS

.sm_counter_cont {
    position: relative;
    width: 200px;
    border-radius: 5px;
    float: left;
    background:#fff;
    padding: 5px 10px;
    font-family: Arial, Helvetica, sans-serif;
    margin-left: 30px;
    margin-top: 10px;
    box-shadow:inset 0px 1px 8px rgba(0,0,0,0.1);
    }
    .sm_santa {
    width: 50px;
    height: 70px;
    position: absolute;
    left: -18px;
    top: -10px;
    }
    .sm_counter_cont h2 {
    font-size: 15px;
    margin: 0 0 2% 0;
    text-align: CENTER;
    color: #000;
    }
    .sm_counter_column {
    color: #000;
    width: 23%;
    float: left;
    border-top: 1px solid #ccc;
    padding: 2% 0px;
    margin: 0px 1%;
    border-radius: 5px;
    background-color: #FFF;
    text-align: center;
    }
    .sm_column_top {
    font-weight: bold;
    }
    .sm_column_bottom {
    text-transform: uppercase;
    font-size: 7px;
    color: #898989;
    }

JAVASCRIPT

/************* HORAS PARA NAVIDAD *************/
function calculateXmasCounter() {
    //calculate
    var now = new Date();
    var current_year = now.getFullYear();
    var xmas = new Date(current_year, 11, 25, 0, 0, 0, 0); //Xmas Date (be careful: 11 is December)
    var hoursleft = 23 - now.getHours();
    var minutesleft = 59 - now.getMinutes();
    var secondsleft = 59 - now.getSeconds();
    var daysleft = Math.floor((xmas - now) / (1000*60*60*24));
    //format 0 prefixes
    if (minutesleft < 10) minutesleft = "0" + minutesleft;
    if (secondsleft < 10) secondsleft = "0" + secondsleft;
    //display
    document.getElementById('xmasdays').innerHTML = (daysleft < 0) ? 0 : daysleft;
    document.getElementById('xmashours').innerHTML = (daysleft < 0) ? 0 : hoursleft;
    document.getElementById('xmasminutes').innerHTML = (daysleft < 0) ? "00" : minutesleft;
    document.getElementById('xmasseconds').innerHTML = (daysleft < 0) ? "00" : secondsleft;
    }
    calculateXmasCounter();
    setInterval(calculateXmasCounter, 1000);


No hay comentarios:

Publicar un comentario

Documental de Hackers