Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda