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

190
Views
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
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!