我有几个可拖拽的元素
<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>
我有以下事件处理程序:
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()
}
为什么只有第一个可拖动元素有效。如果我拖动最后一个可拖动元素,则会立即触发dragend事件。(顺便说一句,我不想使用jQuery UI)这对我来说毫无意义 - 看起来像是一个bug。
我在OSX上使用Chrome v 30。
这是JSFiddle的链接:http://jsfiddle.net/joergd/zGSpP/17/ (编辑:这是以下问题的重复:当我拖动时,dragend、dragenter和dragleave立即触发 - 但我认为原始作者可以使用jQuery UI,而我希望使用HTML5本机方法)