Finrod
Finrod

Reputation: 2550

Using jQuery Draggable with grid and multiple draggable elements

I'm trying to find an better solution to drag multiple elements at once, all elements snapping to a grid, with jQuery UI draggable.

I found a working solution there for the multiple drag part. I adapted it to be able to use the grid with a "round to multiple" function :

function roundM(number, multiple) {
    return Math.round(number / multiple) * multiple;
}

and saving the previous offset. You can see full code in this fiddle.

As you can see, it's working when you drag elements at a normal speed, but when dragging quickly, the other elements do not follow correctly the dragged element.

For now I can keep my solution, but if someone has a better one, I will be glad to test it :)

Thanks

Upvotes: 0

Views: 882

Answers (1)

JsCoder
JsCoder

Reputation: 1733

Have a look at: https://jqueryui.com/draggable/#visual-feedback

Create a helper function resulting in Html representing your selected items and use it as 'visual feedback' when setting up your draggable.

Upvotes: 1

Related Questions