我遇到了Chrome和Opera的一个错误,我想知道它是否已知,如果有,是否有解决方案?
如果我在dragstart事件上更改DOM,它会立即触发dragend事件?!这是一个错误还是背后有一些原因?只发生在Chrome和Opera中.Firefox有效.
我很感激每一个答案.
$('body').on({
dragstart: function(e) {
dragProfilefieldSrcElformid = $(this).attr("data-profilefieldid-formid");
e.dataTransfer = e.originalEvent.dataTransfer;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', $(this).attr("data-profilefieldid"));
// Changing the DOM, fires the dragend Event in Chrome?
$("#plugin_loginlogout_pfcontainer_" + dragProfilefieldSrcElformid).find(".plugin_loginlogout_pf_entryfield").addClass("highlight"); // This doesn't work in Chrome and Opera, but in Firefox
},
dragend: function() {
console.log("dragend");
}
".plugin_loginlogout_pf");Run Code Online (Sandbox Code Playgroud)
编辑:
将DOM Change放在setTimeout函数中似乎解决了这个问题!
我有几个可拖动的元素
<div Class="question-item" draggable="true">Box 1: Milk was a bad choice.</div>
<div class="question-item" draggable="true">Box 2: I'm Ron Burgundy?</div>
<div class="question-item" draggable="true">Box 3: You ate the entire wheel of cheese? </div>
<div class="question-item" draggable="true">Box 4: Scotch scotch scotch</div>
Run Code Online (Sandbox Code Playgroud)
我有以下事件处理程序:
var $questionItems = $('.question-item');
$questionItems
.on('dragstart', startDrag)
.on('dragend', removeDropSpaces)
.on('dragenter', toggleDropStyles)
.on('dragleave', toggleDropStyles);
function startDrag(e){
console.log('dragging...');
addDropSpaces();
e.stopPropagation();
}
function toggleDropStyles(){
$(this).toggleClass('drag-over');
console.log(this);
}
function addDropSpaces(){
$questionItems.after('<div class="empty-drop-target"></div>');
}
function removeDropSpaces(){
console.log("dragend");
$('.empty-drop-target').remove()
}
Run Code Online (Sandbox Code Playgroud)
为什么它只适用于第一个可拖动的.如果我拖动说最后一个draggable - dragend事件立即被触发.(我不想使用jQuery UI btw)
这对我来说毫无意义 - 它看起来像一个bug.
我在OSX上的Chrome …