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

163
Vistas
I want to zoom image but inside the div

I want to zoom the image inside the div but when I am trying to zoom the image the size of the div is also increasing.

<img src="" alt="Image Preview" id="zoom" class="image-preview__image">

   <div class="btn-group mt-2" role="group" aria-label="">
            <button ng-click="Size=100" class="btn btn-sm btn-group btn-outline-info" onclick="zoomout()" >100%</button>
            <button ng-click="Size=200"  class="btn btn-sm btn-group btn-outline-info"  onclick="zoomin()" >200%</button>
            <button ng-click="Size=300" class="btn btn-sm btn-group btn-outline-info">300%</button>
            <button ng-click="Size=400" class="btn btn-sm btn-group btn-outline-info">400%</button>
            </div>
    <script type="text/javascript">

   function zoomin() {
        var GFG = document.getElementById("zoom");
        var currHeight = GFG.clientHeight;
            GFG.style.height = (currHeight + 40) + "px";
    }
    function zoomout() {
        var GFG = document.getElementById("zoom");
        var currHeight = GFG.clientHeight;
            GFG.style.height = (currHeight - 40) + "px";
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of using the width/height, you can use the transform property to scale the image. If you place that image inside a container with overflow:hidden, you can resize the image to any size you like without it overflowing the container and the image will retain its original size for layout purposes.

With that said, you don't need a container with overflow hidden, but without one, the image will visually grow to whatever size you specify, though it will still maintain the intrinsic layout size.

document.querySelectorAll("button").forEach(e => {
  e.addEventListener("click", function(){
    let size = this.getAttribute("ng-click").split("=")[1];
    let image = document.getElementById("zoom");
    image.style.transform = `scale(${size}%)`;
  });
});
.image-container
{
  width: 200px;
  height: 200px;
  overflow: hidden;
}

.image-container img
{
  transition-duration: 1s;
}
<div class="btn-group mt-2" role="group" aria-label="">
  <button ng-click="Size=100" class="btn btn-sm btn-group btn-outline-info">100%</button>
  <button ng-click="Size=200" class="btn btn-sm btn-group btn-outline-info">200%</button>
  <button ng-click="Size=300" class="btn btn-sm btn-group btn-outline-info">300%</button>
  <button ng-click="Size=400" class="btn btn-sm btn-group btn-outline-info">400%</button>
</div>

<div class="image-container">
  <img alt="Image Preview" id="zoom" class="image-preview__image" src="https://via.placeholder.com/200x200">
</div>

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