A Pen by Joel Alejandro Villarreal Bertoldi on CodePen.
Created
September 5, 2020 00:08
-
-
Save joelalejandro/5101c5d8cb15b78f21d1e30edca962a9 to your computer and use it in GitHub Desktop.
Cuenta regresiva
This file contains 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
<div class="cuenta-regresiva"> | |
10 | |
</div> | |
<div class="borde-giratorio"></div> |
This file contains 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
// Hacer una cuenta regresiva que vaya de 10 a 0, actualizando cada 1 segundo | |
// el contenido del elemento cuya clase es .cuenta-regresiva. | |
// Para escribir el contenido de un elemento: .innerHTML | |
// Machete: | |
// Para ejecución diferida: setTimeout(function() { ... }, tiempo); | |
// Para ejecución cíclica: setInterval(function() { ... }, tiempo); | |
// Para detener ejecución cíclica: clearInterval(nombreDeVariableDondeSeGuardóElInterval); | |
let contador= 10; | |
let cuentaRegresiva = document.querySelector('.cuenta-regresiva'); | |
let ciclo = setInterval (function(){ | |
contador -=1; | |
cuentaRegresiva.innerHTML = contador; | |
if(contador === 0) { | |
clearInterval(ciclo); | |
} | |
}, 1000); | |
This file contains 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
* { | |
box-sizing: border-box; | |
} | |
html, body { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
body { | |
display: flex; | |
background: #6d8fff; | |
justify-content: center; | |
align-items: center; | |
} | |
.cuenta-regresiva { | |
font-size: 10rem; | |
font-family: sans-serif; | |
font-weight: bold; | |
color: #ffffff; | |
} | |
.borde-giratorio { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
width: 15rem; | |
height: 15rem; | |
border: 5px solid #fff; | |
margin-left: -7.5rem; | |
margin-top: -7.5rem; | |
border-radius: 50%; | |
border-left-color: transparent; | |
border-right-color: transparent; | |
border-bottom-color: transparent; | |
animation: 1s rotate infinite; | |
} | |
@keyframes rotate { | |
0% { | |
transform: rotate(0deg); | |
} | |
100% { | |
transform: rotate(359deg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment