需要帮助来重新启用可拖动对象的拖动
我有一个可拖动元素
$(".element").draggable({
helper: "clone",
revert: 'invalid',
containment: '#parent',
appendTo: '#parent'
});
我有两个问题:
删除此元素后,原始元素会自动禁用。
关闭锚标记将附加到放置的元素上。单击此“关闭”后,原始元素应再次变为可拖动,并应从可放置的“div”中删除。
我已经为关闭锚点编写了一个处理程序,如下所示,它从可放置元素中删除元素,但不会使其再次可拖动。
$('.cancel a',ui.helper).click(function()
{
$(ui.helper).remove();
$(ui.draggable).draggable('enable');
});
请帮忙。 提前致谢。
I have a draggable element
$(".element").draggable({
helper: "clone",
revert: 'invalid',
containment: '#parent',
appendTo: '#parent'
});
I have two issues:
After this element is dropped, the original gets disabled automatically.
A close anchor tag is appended to the dropped element. On click of this 'close' the original element should again become draggable and should be removed from the droppable 'div'.
I have written a handler for the close anchor as follows, it removes the element from the droppable but it doesn't make it draggable aggain.
$('.cancel a',ui.helper).click(function()
{
$(ui.helper).remove();
$(ui.draggable).draggable('enable');
});
Please help.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个问题的答案是将可拖动元素的禁用选项设置为 false。
在关闭锚点的处理程序上,启用要拖动的可拖动对象。例如,
The answer for the first issue is set the disabled option of the draggable element as false.
On handler for close anchor, enable the draggable object which you want to drag. For example,
我假设您在 Drop 事件中禁用了可拖动功能(?)
$(ui.draggable)
仍然在上下文中。但是,在单击事件中,您无法再访问可拖动对象,而应该直接选择要拖动的元素。例如:
$("#element").draggable("enable")
I assume you disabled the draggable in the the Drop event (?)
$(ui.draggable)
was still in context there.however in the click event you cannot access the draggable object anymore and instead you should select the element you want to drag directley. e.g :
$("#element").draggable("enable")
我做了类似的事情,我创建一个数组来保存删除的可拖动对象的索引,如下所示:
然后要在取消函数中重新启用可拖动对象,您将执行以下操作:
我猜该元素
$(this).parent()
返回的内容与选择器中可放置元素的元素相匹配,如果不是,则必须进行不同的遍历。基本思想是找到被拖动项目的索引,将其存储在
dragged
数组中,其位置等于其被拖放的项目的索引。然后,在取消时,您可以使用可拖动项所在的索引来从与原始可拖动位置匹配的draged
数组中获取值,然后启用该值。I've done a similar thing where I create an array to hold the index of the dropped draggable, like this:
Then to re-enable the draggable in your cancel function, you would do something like this:
I'm guessing that the element that is returned by
$(this).parent()
matches the elements in your selector for the droppable, if not, you'll have to do a different traversal.The basic idea is to find the index of the dragged item, store that in the
dragged
array at the position equal to the index of the item on which it is dropped. Then on cancel, you use the index of the item where the draggable was dropped to get the value from thedragged
array that matches the original draggable position and then enable that.