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

104
Views
Mostrar y ocultar con animación CSS

Mi objetivo es crear una animación al mostrar y ocultar un elemento HTML. Mostrar y ocultar se activa mediante un botón que alterna una clase oculta.

Aquí está mi código:

 const button = document.querySelector('button'); const box = document.querySelector('.box'); button.addEventListener('click', () => { box.classList.toggle('hide'); })
 .box { width:200px; height: 200px; border: 1px solid #000; background-color: gray; margin: 0 auto; opacity: 1; display: block; } .hide { display: none; transition: all 1s ease-out; opacity: 0; }
 <button>Show / Hide</button> <div class="box hide"></div>

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

0

Si desea usar animaciones, no use display:none , puede usar visibility

 const button = document.querySelector('button'); const box = document.querySelector('.box'); button.addEventListener('click', () => { box.classList.toggle('hide'); })
 .box { width:200px; height: 200px; border: 1px solid #000; background-color: gray; margin: 0 auto; opacity: 1; transition: all 1s ease-out; visibility: visible; } .hide { visibility: hidden; transition: all 1s ease-out; opacity: 0; }
 <button>Show / Hide</button> <div class="box hide"></div>

about 4 years ago · Juan Pablo Isaza Report

0

simplemente elimine la display: block de su ocultación y, si desea que la animación se div, agregue la animación también:

 const button = document.querySelector('button'); const box = document.querySelector('.box'); button.addEventListener('click', () => { box.classList.toggle('hide'); })
 .box { width:200px; height: 200px; border: 1px solid #000; background-color: gray; margin: 0 auto; opacity: 1; transition: all 1s ease-out; display: block; } .hide { transition: all 1s ease-out; opacity: 0; }
 <button>Show / Hide</button> <div class="box hide"></div>

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!