如何实现触发“恢复”当draggable-element超过“margin”时可放置元素。 jQuery
当元素 $('.ship') 位于其他 $('.ship') 元素或超过 $('.ship') 的“边距”时,我需要触发“恢复”。它适用于“填充”和“边框”,但不适用于“边距”。我该怎么做?这是我的代码片段:
$('.ship').draggable({
containment : "#content",
snap : "#board table td",
snapMode : "inner",
revert : "invalid",
opacity: 0.7,
stack: '.ship',
});
$('.ship').droppable({
drop: function(e, ui) {
ui.draggable.draggable('option', 'revert', true);
},
tolerance: 'touch'
});
$('#board').droppable({
drop: function(e, ui) {
$(ui.draggable).css('margin', '3px');
ui.draggable.draggable('option', 'revert', false);
},
tolerance: 'fit'
});
I need that "revert" triggering when element $('.ship') is over other $('.ship') element or over "margin" of $('.ship'). It works over "padding" and "border", but don't work over "margin". How do I do this? Here is the piece of my code:
$('.ship').draggable({
containment : "#content",
snap : "#board table td",
snapMode : "inner",
revert : "invalid",
opacity: 0.7,
stack: '.ship',
});
$('.ship').droppable({
drop: function(e, ui) {
ui.draggable.draggable('option', 'revert', true);
},
tolerance: 'touch'
});
$('#board').droppable({
drop: function(e, ui) {
$(ui.draggable).css('margin', '3px');
ui.draggable.draggable('option', 'revert', false);
},
tolerance: 'fit'
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有直接的答案,但如果您找不到使用边距的方法,请在 .ship 周围包裹一个容器,占据与当前边距相同的区域,并使该容器可放置。
I don't have the direct answer but if you can't find a way to work with margins, wrap a container around .ship, occupy the same area as your current margin would and make that container droppable.