This is a solution to the Todo app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Add new todos to the list
- Mark todos as complete
- Delete todos from the list
- Filter by all/active/complete todos
- Clear all completed todos
- Toggle light and dark mode
- Bonus: Drag and drop to reorder items on the list
- Solution URL: GitHub
- Live Site URL: GitHub Live
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- Mobile-first workflow
This is the drag and drop code below:
listItem.draggable = true;
listItem.addEventListener('dragstart', e => {
draggedItem = e.target;
});
listItem.addEventListener('dragover', e => {
e.preventDefault();
});
listItem.addEventListener('dragenter', e => {
e.target.classList.add('drag-over');
});
listItem.addEventListener('dragleave', e => {
e.target.classList.remove('drag-over');
});
listItem.addEventListener('drop', e => {
e.target.classList.remove('drag-over');
if (draggedItem !== null) {
const items = Array.from(itemsList.getElementsByClassName('list-item'));
const currentIndex = items.indexOf(e.target);
const draggedIndex = items.indexOf(draggedItem);
if (currentIndex > draggedIndex) {
itemsList.insertBefore(draggedItem, e.target.nextSibling);
} else {
itemsList.insertBefore(draggedItem, e.target);
}
draggedItem = null;
}
});
I need to learn how to do implement more advanced interactive features such as the drag and drop.
- W3Schools - This site helps me whenever I need a reminder of how to use certain code
- ChatGPT - This helped me with the code for the dragg & drop feature
- Frontend Mentor - @rnsnceman
- Instagram - @yurikoller