Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
Cuenta ascendente de Javascript, agregue css para el tipo y tamaño de fuente, también aumente el tamaño del número

este javascript cuenta hacia arriba. Pero no tiene CSS para el tipo, tamaño y color de fuente. Necesito ese CSS . Además, el número inicial comienza como 0. Pero quiero que el número inicial comience con un número mayor. es decir: 12434556. Por favor, ayúdame. Gracias.

 <div class='countdown'></div> <script type="text/javascript"> function pad(num, size) { var s = num + ""; while (s.length < size) s = "0" + s; return s; } function initCountdown() { setTimeout(function() { current_wait++; if (current_wait <= waits.length) { var countdowns = document.getElementsByClassName('countdown'); for (var i = 0; i < countdowns.length; i++) { var number = parseInt(countdowns[i].innerHTML); number++; countdowns[i].innerHTML = pad(number, 2); window.localStorage.setItem('_setCountdownTimer', JSON.stringify({'initial_number': number, 'current_wait': current_wait})) } initCountdown(); } }, waits[current_wait] * 1000); } var waits = [8, 16, 19, 26, 44, 66, 88, 99, 121]; //t-val var _locatStorage = JSON.parse(window.localStorage.getItem('_setCountdownTimer')), initial_number = 0, current_wait = 0; _locatStorage ? ( initial_number = parseInt(_locatStorage.initial_number), current_wait = parseInt(_locatStorage.current_wait) ):( window.localStorage.setItem('_setCountdownTimer', JSON.stringify({'initial_number': 0, 'current_wait': 0})), initial_number = 0, current_wait = 0 ) var countdowns = document.getElementsByClassName('countdown'); for (var i = 0; i < countdowns.length; i++) { countdowns[i].innerHTML = pad(initial_number, 2); } initCountdown(); </script>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Agregar CSS es simple: puede agregarlo en línea en la etiqueta div de esta manera

 <div class="countdown" style=" font-size: 6em; font-family: 'Courier New', Courier, monospace; color: red; font-weight: 800; " ></div>

o puede agregar una etiqueta de estilo justo antes de su etiqueta <script> como esta

 <style> .countdown { font-size: 6em; font-family: 'Courier New', Courier, monospace; color: red; font-weight: 800; } </style>

Además, has usado initial_number varias veces en el código. Cuando hace eso, siempre es una buena idea definir una variable en la parte superior y usar su valor en su código.

 const INIT_NUM = 2335343234; function initCountdown() { setTimeout(function () { current_wait++; if (current_wait <= waits.length) { var countdowns = document.getElementsByClassName('countdown'); for (var i = 0; i < countdowns.length; i++) { var number = parseInt(countdowns[i].innerHTML); number++; countdowns[i].innerHTML = pad(number, 2); window.localStorage.setItem( '_setCountdownTimer', JSON.stringify({ initial_number: number, current_wait: current_wait, }) ); } initCountdown(); } }, waits[current_wait] * 1000); } var waits = [8, 16, 19, 26, 44, 66, 88, 99, 121]; //t-val var _locatStorage = JSON.parse( window.localStorage.getItem('_setCountdownTimer') ), initial_number = INIT_NUM, current_wait = 0; _locatStorage ? ((initial_number = parseInt(_locatStorage.initial_number)), (current_wait = parseInt(_locatStorage.current_wait))) : (window.localStorage.setItem( '_setCountdownTimer', JSON.stringify({ initial_number: INIT_NUM, current_wait: 0 }) ), (initial_number = INIT_NUM), (current_wait = 0));

También asegúrese de que cuando use este nuevo código, borre su almacenamiento local, de lo contrario, siempre usará el valor anterior

Puede borrar el valor escribiendo esto en la consola de desarrollo de su navegador

 window.localStorage.removeItem('_setCountdownTimer');

Puede encontrar la demostración aquí

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda