jQuery draggable + droppable: how to snap dropped element to dropped-on element

前端 未结 7 1277
无人及你
无人及你 2020-11-30 19:42

I have my screen divided into two DIVs. In the left DIV I have a few 50x50 pixel DIVs, in the right DIV I have an empty g

7条回答
  •  攒了一身酷
    2020-11-30 20:28

    Thanks for your post - it helped me in the right direction. I find it a bit cleaner to set the position properties of the draggable object instead of messing with the HTML code. This sets the position to the top left corner of the droppable object, but you can modify to have it centered as well.

    drop: function(event, ui) {
       $(ui.draggable).css('top', $(this).position().top);
       $(ui.draggable).css('left', $(this).position().left);
    }
    

提交回复
热议问题