简体   繁体   English

自定义拖放HTML5

[英]custom drag and drop HTML5

I am trying to use drag and drop to reorder elements in the list (pure javascript). 我正在尝试使用拖放来重新排序列表中的元素(纯JavaScript)。 I would like to stylise the "ghost element" during the drag operation. 我想在拖动操作中对“鬼元素”进行样式化。 Since I read that there is no way how to do that standartly, I am creating duplicate element (styled as I want) positioned exactly where original element should be during drag operation and its position is updated inside ondrag event. 由于我读到没有办法正常地进行操作,因此我正在创建重复元素(按我的需要设置样式),将其精确定位在拖动操作期间原始元素应位于的位置,并且在ondrag事件中更新了其位置。

Problem is that since this duplicate element is always exactly under cursor it is impossible to capture dragover or dragenter events on other elements. 问题在于,由于此重复元素始终始终位于光标之下,因此无法捕获其他元素上的拖动或拖动事件。 No matter where in the DOM is the "duplicate" element linked it always blocks ondragover. 无论在DOM中的何处链接的“重复”元素始终会阻止ondragover。 If I move the duplicate element so its not under the cursor it works but that defeats the purpose of seamless duplicate element. 如果我移动重复元素,使其不在光标下方,则可以正常工作,但这违反了无缝重复元素的目的。

Is there some way how this duplicate element would be ignored so elements that are underneath it would get the ondragover event instead? 是否有某种方式可以忽略此重复元素,以便使其下面的元素获得ondragover事件呢? Normally event just bubbles towards parent of where the duplicate element is linked. 通常情况下,事件只是朝链接重复元素所在位置的父对象冒泡。

Got it working. 得到它的工作。 It seems that it works (ghost element is not blocking the events) if its class has : 如果其类具有以下功能,则它似乎可以正常工作(ghost元素未阻止事件):

.duplicateGhostElementClass {
  pointer-events: none;
}

Perhaps it saves someone some time. 也许它可以节省一些时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM