Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
La animación Javascript Appear-Disappear no funciona

Quiero hacer que h1 desaparezca y después de 3 segundos vuelva a aparecer. Desaparece pero no vuelve a aparecer. ¿O necesito un estilo en línea para ello? ¿Y cualquier otro bucle útil para esto, excepto si?

 let head1 = document.querySelector(".asd") let head1style = getComputedStyle(head1); let head1disp = head1style.display; let changedisp = function() { if (head1disp === "block") { head1.style.display = "none"; } else if (head1disp === "none") { head1.style.display = "block" } else { console.log("Something Wrong!") } }; setInterval(changedisp, 3000);
 h1 { display: block; }
 <body> <h1 class="asd">Look at me!</h1> <script src="app.js"></script> </body> </html>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No necesita JavaScript para eso en un navegador moderno. Las animaciones CSS con fotogramas clave son totalmente capaces de ofrecer el mismo efecto:

 <style> @keyframes fade-out-in { 0% { opacity: 1; } 25% { opacity: 0; } 75% { opacity: 0; } 100% { opacity: 1; } } .box { animation: fade-out-in 5000ms; /* wait time at the beginning */ animation-delay: 2000ms; } </style> <div class="box"> Hello World </div>

Probablemente necesitará ajustar el tiempo. Obtenga más información sobre las animaciones de fotogramas clave CSS en este fantástico artículo: https://www.joshwcomeau.com/animation/keyframe-animations/

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar setTimeout para hacerlo una vez.

 const h1 = document.querySelector('h1'); h1.style.display = 'none'; setTimeout(() => h1.style.display = 'block', 3000);

O puede usar setInterval para hacerlo cada 3 segundos.

 const h1 = document.querySelector('h1'); function switchDisplay() { if (h1.style.display === 'block') h1.style.display = 'none'; else h1.style.display = 'block'; } setInterval(switchDisplay, 3000);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!