JSFiddle - React, Tailwind, and code Playground
by joergd
HTML
<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>
<!-- <div class="empty-drop-target drag-over"></div> -->
CSS
.question-item {
background-color: #ccc;
padding:1em;
margin: 1em;
border: 2px solid #777;
}
.drag-over {
background-color: #aaa;
border: 2px dashed #000;
}
.empty-drop-target {
height:1em;
margin: .5em;
border:1px dashed #666;
background-color: #fff;
}
/* .empty-drop-target .drag-over {
background-color: red;
} */
JavaScript
var $questionItems = $('.question-item');
$questionItems
.on('dragstart', startDrag)
.on('dragend', removeDropSpaces)
.on('dragenter', toggleDropStyles)
.on('dragleave', toggleDropStyles);
function startDrag(){
console.log('dragging...');
addDropSpaces();
}
function toggleDropStyles(){
$(this).toggleClass('drag-over');
console.log(this);
}
function addDropSpaces(){
$questionItems.after('<div class="empty-drop-target"></div>');
}
function removeDropSpaces(){
$('.empty-drop-target').remove();
console.log('dragend');
}