revert 'invalid' with grid doesn't return to start position with jQuery UI Draggable

前端 未结 1 1720
情书的邮戳
情书的邮戳 2021-01-18 23:27

In a nutshell, if you use draggable with a grid and set revert: \'invalid\' on draggable items they don\'t return to exactly the same place you started dragging them from. T

1条回答
  •  北海茫月
    2021-01-19 00:10

    grid option documentation says:

    Snaps the dragging helper to a grid, every x and y pixels.

    So it looks like grid was designed to be used only with some kind of helper. And really, if you use helper: "clone" things are good: helper returns near the place of original instance and

    Yes, this looks like a bug in UI. But there's a workaround: use helper for dragging:

    $(".dragme").draggable({
        revert: true,
        helper: "clone",
        grid: [50,50]
    });
    

    This workaround introduces other weird bug: after a valid drop on droppable area helper gets destroyed and original instance exists in it's place (you can see it at fiddle).

    This bug somehow solved for draggable with connectToSortable options. Maybe it's possible to solve the bug in your case too.

    Also, I suspect the whole mess is because of this chunk of code in draggable.

    0 讨论(0)
提交回复
热议问题