【发布时间】:2015-09-30 11:33:41
【问题描述】:
我有许多基本相同的 div,它们分布在屏幕上。每一个都是 jQuery 可在 x 轴上拖动的。你可以把它想象成一个带有许多手柄的 ui-slider。 如何编写一个函数来检查我可能拖动的任何 div 是否与任何其他 div 或 div 重叠?
我想要一个全局状态来指示是否有任何重叠,以及一种确定只有重叠的 div 的 id 的方法。
这是我迄今为止创建的,但我不太了解比较宽度/高度/偏移等的算法。请,我需要帮助。
<div class="dragable">
<div class="dragable">
<div class="dragable">
<div class="dragable">
--
function collisionChecker(activeDiv, anyOtherDiv) {
//do activeDiv and anyOtherDiv overlap? Yes - return true
}
$('.dragable').draggable({
drag: function( event, ui ) {
$('.dragable').not(this).each(function(){
$('#result').text( collisionChecker($(ui.helper), $(this)) );
});
}
});
【问题讨论】:
标签: jquery collision-detection jquery-ui-draggable