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

181
Vistas
Implementing a zoom function but can't get it to work properly
    let scale = 1;
    let translateX = 0;
    let translateY = 0;
    let element = document.querySelector('img');

    let zoom = ( e ) => {

        e.preventDefault();

        let formerScale = scale;
        scale -= (e.deltaY / 5000);
        let elemRect = element.getBoundingClientRect();
        let mX = e.clientX - elemRect.x;
        let mY = e.clientY - elemRect.y;

        let newMX = mX - translateX ;
        let newMY = mY - translateY;
        
        let x = mX - (newMX * (scale / formerScale));
        let y = mY - (newMY * (scale / formerScale));
        translateX = x;
        translateY = y;

        element.style.transform = `translate(${x}px, ${y}px) scale(${scale})`;

    }
    element.addEventListener('mousewheel', wheelZoom);

I am having trouble getting this zoom based on mouse position to work. I got this image with a 3:2 aspect ratio as the elem and the zoom isn't behaving the way its supposed to. It is zooming, but it is traveling away from the area where the mouse is rather than adjusting to it. Would really appreciate some input on the implementation of the zoom here. Thank you!!

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