Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html lang="pt-br">
- <head>
- <meta charset="utf-8" />
- <title>Cronômetro com Javascript</title>
- <style>
- *{
- margin:0;
- padding:0;
- }
- body{
- background:#CCC;
- color:#FFF;
- font-family:Arial, Helvetica, sans-serif;
- text-align:center;
- }
- #topo{
- background:#069;
- height:50px;
- border-bottom:2px solid #006;
- padding-top: 10px;
- }
- h2 a{
- color:#069;
- text-decoration:none;
- }
- h2 a:hover{
- color:#006;
- }
- input{
- background:#ccc;
- width:600px;
- height:200px;
- line-height:200px;
- font-size:240px;
- border:none;
- }
- #cro{
- width: 600px;
- clear:both;
- margin-bottom: 20px;
- margin-left: auto;
- margin-right:auto;
- }
- .mybtn{
- cursor: pointer;
- font-size:18px;
- clear:both;
- margin-bottom: 6px;
- padding: 10px;
- border-radius: 10px;
- width: 450px;
- }
- .container{
- width:100%;
- }
- .zeb{
- background-color: #88AAAA;
- }
- </style>
- <script type="text/javascript">
- var tempo = 0; // tempo em segundos
- var working = false; // sinaliza se o timer está ativado
- var intervaloID = 0; // identificação do intervalo que permite limpá-lo
- function exibeTempo(){
- let min = parseInt(tempo/60); // Pega a parte inteira dos minutos
- let seg = tempo%60; // Calcula os segundos restantes
- let smin = min.toString().padStart(2, '0'); // Formata o número em duas casas
- let sseg = seg.toString().padStart(2, '0');
- let tempoTela = smin + ':' + sseg; // Variável para formatar no estilo cronômetro
- document.querySelector(".cronometro").value = tempoTela;
- tempo--;
- if (tempo < 0){ // zera temporizador
- working = false;
- clearInterval(intervaloID);
- document.querySelector(".cronometro").style.backgroundColor = '#ccc';
- }
- else if(tempo < 15){ // alerta dos 15 seg. finais
- document.querySelector(".cronometro").style.backgroundColor = 'red';
- }
- }
- function temporizador(t){
- if (working == false){
- working = true;
- tempo = t;
- exibeTempo();
- intervaloID = setInterval(exibeTempo, 1000); // 1s
- }
- }
- </script>
- </head>
- <body>
- <div class='container'>
- <div id="topo">
- <h1>Debate Eleições 2022 - Cronômetro</h1>
- </div>
- <div id="cro">
- <input type="text" class="cronometro" value="00:00" readonly/>
- </div><br />
- <button class='mybtn' onclick="temporizador(180)">3 minutos (Apresentação Inicial)</button><br />
- <button class='mybtn zeb' onclick="temporizador(300)">5 minutos (Bloco perguntas, Considerações Finais)</button><br />
- <button class='mybtn' onclick="temporizador(60)">1 minuto (Pergunta/Tréplica)</button><br />
- <button class='mybtn zeb' onclick="temporizador(120)">2 minutos (Resposta/Réplica)</button><br />
- <button class='mybtn' onclick="window.location='index.html';">Limpar</button>
- </div>
- </body>
- </html>
Advertisement