Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否检测拖动对象下方的多个元素?Javascript/Jquery_Javascript_Jquery_Html_Drag And Drop_Draggable - Fatal编程技术网

是否检测拖动对象下方的多个元素?Javascript/Jquery

是否检测拖动对象下方的多个元素?Javascript/Jquery,javascript,jquery,html,drag-and-drop,draggable,Javascript,Jquery,Html,Drag And Drop,Draggable,我有一个按钮,使用jquery通过以下代码以友好方式创建对象并使其“可拖动”: createNewDiv(divId); <--local function that creates a new div with id=divId $("#"+divId).draggable(); createNewDiv(divId) 我想最好的办法是做如下事情: var bufferInteger = 0, dragParent = $( container ), dragChildren = {}

我有一个按钮,使用jquery通过以下代码以友好方式创建对象并使其“可拖动”:

createNewDiv(divId); <--local function that creates a new div with id=divId
$("#"+divId).draggable();

createNewDiv(divId) 我想最好的办法是做如下事情:

var bufferInteger = 0, dragParent = $( container ), dragChildren = {};
(function layerCalculation(){
    dragParent.find('.draggable').each(function(index, val){
        var child = $(val), 
          childOffset = {
            top    : child.offset().top,
            left   : child.offset().left,
            width  : child.width(),
            zIndex : child.css('z-index')
          };
        dragChildren[child.attr('id')].top = childOffset.top;
        dragChildren[child.attr('id')].left = childOffset.left;
        dragChildren[child.attr('id')].width = childOffset.width;
        dragChildren[child.attr('id')].zIndex = childOffset.zIndex;
    });
}());

function detectHover(ui){
    var currentlyOver,
        uiElement = ui.helper[0],
        underStacked = dragChildren, 
        draggedItem = {
        id     : uiElement.id,
        offset : {
            left : uiElement.offsetLeft,
            top  : uiElement.offsetTop
        }
    };
    underStacked.splice(understacked.indexOf(draggedItem.id), 1);

    for (var i in underStacked){
        if ((underStacked[i].left <= draggedItem.offsetLeft <= (underStacked[i].left - - underStacked[i].width)) {
            currentlyOver = underStacked.id;
        } else if (...) {
            // do some logic here to calculate draggedItem.offsetLeft + draggedItem.width
        }
    }
    if (typeof currentlyOver !== 'undefined'){
        return currentlyOver;
    } else {
        return false;
    }
}
$('.draggable').bind({
    dragstart : function(){
        layerCalculation();
    },
    dragend : function(){
        layerCalculation();
    },
    drag : function(event, ui){
        bufferInteger++;
        if (bufferInteger > 9){
            bufferInteger = 0;
            detectHover(ui);
            ...
            // do something with return ID here.
        }
    }
});
var bufferInteger=0,dragParent=$(容器),dragChildren={};
(功能层计算(){
dragParent.find('.draggable')。每个(函数(索引,val){
var child=$(val),
childOffset={
top:child.offset().top,
左:child.offset().left,
宽度:child.width(),
zIndex:child.css('z-index')
};
dragChildren[child.attr('id')].top=childOffset.top;
dragChildren[child.attr('id')].left=childOffset.left;
dragChildren[child.attr('id')].width=childOffset.width;
dragChildren[child.attr('id')].zIndex=childOffset.zIndex;
});
}());
函数检测器(ui){
var currentlyOver,
uiElement=ui.helper[0],
未打包=拖拉儿童,
draggedItem={
id:uiElement.id,
偏移量:{
左:uiElement.offsetLeft,
顶部:uiElement.offsetTop
}
};
未封装拼接(未封装索引of(draggedItem.id),1);
对于(未包装的var i){

如果((未压缩[i]。左侧)您是否使用DragTable的
堆栈
选项?是的,我仅在开始拖动时使用它,通过更改z-indexcan u,拖动的对象将位于其他元素的前面请为上述代码共享一个小提琴,因为我试图在vanilla js中实现同样的效果