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

133
Views
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 answers
Answer question

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 Report
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!