diff --git a/dragdrop.js b/dragdrop.js new file mode 100644 index 0000000..ffa9359 --- /dev/null +++ b/dragdrop.js @@ -0,0 +1,25 @@ +const dropContainer = document.getElementById("dropcontainer"); +const fileInput = document.getElementById("input-file"); + +dropContainer.addEventListener( + "dragover", + (e) => { + // prevent default to allow drop + e.preventDefault(); + }, + false +); + +dropContainer.addEventListener("dragenter", () => { + dropContainer.classList.add("drag-active"); +}); + +dropContainer.addEventListener("dragleave", () => { + dropContainer.classList.remove("drag-active"); +}); + +dropContainer.addEventListener("drop", (e) => { + e.preventDefault(); + dropContainer.classList.remove("drag-active"); + fileInput.files = e.dataTransfer.files; +}); diff --git a/index.html b/index.html index 33310c3..bb7a6df 100644 --- a/index.html +++ b/index.html @@ -18,471 +18,8 @@