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

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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