Can someone please help me!
I am working on assignment with drag & drop and localstorage.
This is my first time wring a code involving localstorage. I’m creating
someting like kanban board.
The problem I am having right now is, I have no idea how am i going
to write code for getItem and make my card stay at the position where i drop
it after page refresh. I already write for setItem part and I think it works.
I can see the position change in the localstorage everytime I change it’s place.
Here is what i’ve tried so far
const todos = document.querySelectorAll(".todo");
const all_status = document.querySelectorAll(".box")
todos.forEach((todo) => {
todo.addEventListener("dragstart", dragStart);
todo.addEventListener("dragend", dragEnd);
});
function dragStart() {
draggableTodo = this;
setTimeout(() => {
this.style.display = "none";
}, 0);
console.log("dragStart");
}
function dragEnd() {
draggableTodo = null;
setTimeout(() => {
this.style.display = "block";
}, 0);
console.log("dragEnd");
}
all_status.forEach((box) => {
box.addEventListener("dragover", dragOver);
box.addEventListener("dragenter", dragEnter);
box.addEventListener("draleave", dragLeave);
box.addEventListener("drop", dragDrop);
});
function dragOver(e) {
e.preventDefault();
//console.log("dragOver");
}
function dragEnter() {
console.log("dragEnter");
}
function dragLeave() {
console.log("dragLeave");
}
function dragDrop() {
this.appendChild(draggableTodo);
var left = this.offsetLeft;
var top = this.offsetTop;
localStorage.setItem("left", left);
localStorage.setItem("top", top);
console.log("localStorage");
}