...

/

Dragging and Dropping Cards

Dragging and Dropping Cards

Shift cards around by dragging and dropping.

We'll cover the following...

Exercise:

Make it possible to drag and drop cards.

Source code: Use the PomodoroTracker6 folder as a starting point. The result is in PomodoroTracker7.

Solution: There is a draggable attribute in HTML5. When using this attribute, you will be able to automatically move draggable elements by holding down the mouse button. Let’s make our selected card draggable:

Press + to interact
const cardTemplate = ( { task, id, columnIndex } ) => `
<div class="task js-task ${ task.selected ? 'selected' : '' }"
data-id="${id}"
draggable="${ task.selected ? "true" : "false" }"
data-column-index="${columnIndex}">
...
</div>
`;

So far we have only added one attribute, but as soon as you start dragging the selected card, you can see that a higher opacity version of the selected card follows the mouse cursor as long as you hold the mouse button down.

The question arises, how can you find out about the draggable html5 attribute during an interview? The answer is simple: Google ...