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

198
Views
Konva.js: dynamic groups for dragging

I am trying to implement quite a complex layout in Konva. I need the behavior similar to this codepen. I have multiple shapes, and whenever I start dragging any of them, all the underlying shapes should be dragged with it. In the codepen, though, for the sake of simplicity, this logic is only implemented for the topmost rectangle (red).

So here's how I thought it was gonna work.

  1. On mousedown event, dynamically create a draggable group, include all the needed shapes
  2. On dragend event, ungroup elements

The demo seems to work ok, but the problem is that group always has a position equal to (0, 0), wherever it was at the time I started dragging. You can drag the red rect around for some time, then open your console and see {x: 0, y: 0}. But how do I make it have coordinates relative to the layer?

I need it because sometimes when the dragging ends, I need to animate movement of the whole group to a specific location, and the fact that the initial position of the group is always (0, 0) makes it hard to calculate the destination position.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Positions of all nodes in Konva are relative. And by default, position of every node is {0, 0}.

When you create a group, you can set another position for it. But remember that you may need to adjust positions of all children (rectangles) because their positions will be relative to the moved group.

Also, you can initiate dragging of rectangles manually, without group.

r1.on('mousedown', () => {
  r1.startDrag();
  r2.startDrag();
  r3.startDrag();
});
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!