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

191
Views
Reduciendo el tamaño de la imagen cuando se usa transform: scale()

Tengo un problema con "acercar" una imagen cuando se recorta el transform-origin: center center de la imagen

Necesito tener la posibilidad de ver la imagen completa al desplazarme por el contenedor de la imagen.

PD: transform-origin: left top corrige el problema de la imagen recortada pero deja un espacio vacío en el lado izquierdo del contenedor

HTML:

 <div class="btn-wrap"> <button id="zoomIn">zoom +</button> <button id="zoomOut">zoom -</button> </div> <div class="image-container"> <img src="https://webmeup.com/upload/blog/lead-image-105.png" /> </div>

JS:

 const DEFAULT_SCALE_STATE = 1; const MAX_SCALE_STATE = 2.25; const SCALE_STEP = 0.25; let imageScale = 1; const handleZoomIn = () => { if (imageScale < MAX_SCALE_STATE) { imageScale = imageScale + SCALE_STEP; setImageStyles(); } }; const handleZoomOut = () => { if (imageScale > DEFAULT_SCALE_STATE) { imageScale = imageScale - SCALE_STEP; setImageStyles(); } }; const img = document.querySelector('img'); const setImageStyles = () => { img.style.transform = `scale(${imageScale})`; img.style.transformOrigin = `center center`; }; document.getElementById('zoomIn').addEventListener('click', handleZoomIn); document.getElementById('zoomOut').addEventListener('click', handleZoomOut);

código: stackblitz

ejemplo stackblitz

about 4 years ago · Juan Pablo Isaza
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!