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

127
Vistas
Unable to resize Rect with mouse events

I am trying to resize the rectangle inside the SVG by using mouse events. Currently, I am working on the right bottom edge, for that, I created another circle shape and I am applying events on that shape to resize the rectangle. I don't know why when I start resizing it first it gets small and then starts resizing.

const min = 54;
            let initialWidth = 0, initialHeight = 0, mouseX = 0, mouseY = 0;
rightBottomCorner.addEventListener('mousedown', function(evt: any) {
              getMousePositions(evt);
              getElementDimensions();
              evt.stopPropagation();
              window.addEventListener('mousemove', scale);
              window.addEventListener('mouseup', removeScale);
            });

            function getMousePositions(evt: any) {
              mouseX = evt.pageX;
              mouseY = evt.pageY;
            }

            function getElementDimensions() {
              selectedRect = rect;
              initialWidth = selectedRect.clientWidth;
              initialHeight = selectedRect.clientHeight;
            }

            function scale(evt: any) {
              selectedRect = rect;
              const width = initialWidth + (evt.pageX - mouseX);
              const height = initialHeight + (evt.pageY - mouseY);
              if (width > min) {
                selectedRect.setAttributeNS(null, 'width', width as unknown as string);
              }
              if (height > min) {
                selectedRect.setAttributeNS(null, 'height', height as unknown as string);
              }
            }

            function removeScale() {
              window.removeEventListener('mousemove', scale);
            }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are passing the functions to addEventlistener before they are defined.You have to move the rightBottomCorner.addEventListener function below your removeScale function. Then the resizing works.

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