[英]How to select the div which the item is being dragged into on hover, using jQuery UI sortable
好的,所以我有一个可排序的普通jQuery UI,并且需要选择将元素放入其中的div。 我通常通过在接收到的事件中使用ui.item.parent('div')来获取此信息。
但是,在over事件中,变量与元素的发送者(从中拖动元素)有关,而不是与鼠标悬停的内容有关。 因此,如何选择要放置元素的位置。
我目前有一个示例,仅打印父元素的偏移量:
$(".connectedSortable").sortable({
over:function(event,ui){
console.log(ui.item.closest('div').offset())
},
connectWith: ".connectedSortable"
}).disableSelection();
编辑:
我创建了一个非常简单的示例来展示我在做什么:
基本上,当您将第一个表中的一行拖到下一个表中时,您会在控制台中看到该行的offset.left为0。我需要新表的offset.left。
您可以使用占位符,然后选择占位符类的父级。
$( ".sortable" ).sortable({
connectWith: '.sortable',
helper: 'clone',
placeholder: "placeholder",
over:function(event,ui){
console.log($('.placeholder').parent().attr('id'));
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.