drag and drop zone with child nodes

喜你入骨 提交于 2021-02-08 09:22:22

问题


I have a drag and drop zone with multiple child nodes.

The main element has dropenter and dropleave events. But if you drag a file inside the main element and over a child node, the dropleave is triggered.

How to handle it so the dropleave only is called when the dragged element and mouse is outside the main element?

http://jsfiddle.net/4cspcsc4/

<div class="drop">
    Drop here
    <div class="img"></div>
</div>

$('.drop').on('dragenter', function(e){
    $(this).addClass('highlight');
})
.on('dragleave', function(e){
    $(this).removeClass('highlight');
})

.drop {
    height:200px;
    width:200px;
    background:#aaa;
}

.drop.highlight {
    border:2px dashed black;
}

.img {
    height:100px;
    width:100px;
    background:red;
}

回答1:


Add this CSS

.drop * {
    pointer-events:none;
}

Here is a fiddle http://jsfiddle.net/b7pgbhva/



来源:https://stackoverflow.com/questions/27731945/drag-and-drop-zone-with-child-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!