Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
Reducing the size of the image when using transform: scale()

I have a problem with "zoom in" an image when the transform-origin: center center part of the image is cropped

I need to have the possibility to view the whole image when scrolling the container of the image

PS: transform-origin: left top fixes cropped image issue but leave empty space on the left side of the container

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);

code: stackblitz

example stackblitz

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda