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

144
Views
¿Cómo cambio el tamaño de img al hacer clic y lo devuelvo a la normalidad al alternar usando javascript?

Quiero que una imagen en un archivo html cambie de tamaño en un 50 % y vuelva al tamaño normal con un segundo clic. Traté de hacerlo de la misma manera que lo hago con el mouseover pero no funciona. ¿Alguien tiene alguna idea sobre cómo hacer esto en javascript?

código HTML -

 <article id="featuredartists"> <h2>Featured Artists</h2> <div class="artistlist group"> <ul class="group"> <li><img src="images/artists/Barot_Bellingham_tn.jpg" alt="Photo of Barot Bellingham" onclick="func3()"></li> </ul> </div> </article>

javascript externo -

 function func3() { x = document.getElementsByTagName("img")[11]; x.height = 50%; x.width = 50%; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un ejemplo mucho más simple que usa transformaciones. Simplemente cambie una clase al hacer clic.

 document.querySelector("img").addEventListener("click", function(){ this.classList.toggle("half"); });
 img { transition-duration: 0.4s; } img.half { transform: scale(0.5); }
 <img src="https://via.placeholder.com/100x100"/>

Si realmente desea que cambie el tamaño del elemento y el flujo, puede cambiar el ancho/alto dentro de la clase .half .

 document.querySelector("img").addEventListener("click", function(){ this.classList.toggle("half"); });
 img { transition-duration: 0.4s; width: 100px; height: 100px; } img.half { width: 50px; height: 50px; }
 <img src="https://via.placeholder.com/100x100"/>

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!