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

189
Views
La ventana emergente HTML solo funciona cuando se hace clic cada 2 veces

Soy nuevo en html y css. Ahora estoy aprendiendo sobre la ventana emergente y me he encontrado con un problema. Echa un vistazo a este sencillo violín: https://jsfiddle.net/74agLucr/

 function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); }
 .popup { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* The actual popup */ .popup .popuptext { visibility: hidden; width: 160px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -80px; } /* Popup arrow */ .popup .popuptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } /* Toggle this class - hide and show the popup */ .popup .show { opacity: 0; /* add this */ visibility: visible; -webkit-animation: fadeIn 3s; animation: fadeIn 3s; } @-webkit-keyframes fadeIn { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } } @keyframes fadeIn { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } }
 <h2>Popup</h2> <div class="popup" onclick="myFunction()">Click me to toggle the popup! <span class="popuptext" id="myPopup">A Simple Popup!</span> </div>

Cuando hace clic en el texto, la ventana emergente aparece y desaparece en breve. Cuando se vuelve a hacer clic, no hará nada. Debo hacer clic dos veces para que vuelva a aparecer. ¿Podría alguien indicarme la dirección correcta y ayudarme a comprender cuál es el problema?

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

0

El problema con la ventana emergente es que alternar agrega una clase si no se agregó y elimina si ya se agregó. Es por eso que tienes que hacer clic dos veces para que funcione. Puede intentar configurar setTimeout() para que se desactive después de 3 segundos de animación.

 function myFunction() { var popup = document.getElementById("myPopup"); if(!popup.classList.contains("show")){ popup.classList.add("show"); setTimeout(()=>{popup.classList.remove("show");}, 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!