Full page drag and drop files website with HTML

JavascriptWeb DevelopmentFront End Scripts

For full page drag and drop files, try the following code:

var myDrop = document.getElementById('dropZone');
function displayDropZone() {
   myDrop.style.visibility = "visible";
}
function hideDropZone() {
   myDrop.style.visibility = "hidden";
}
function allowDrag(ev) {
   if (true) {
      ev.dataTransfer.dropEffect = 'copy';
      ev.preventDefault();
   }
}
function handleDrop(ev) {
   ev.preventDefault();
   hideDropZone();
   alert('This is Drop!');
}
window.addEventListener('dragenter', function(ev) {
   displayDropZone();
});
myDrop.addEventListener('dragenter', allowDrag);
myDrop.addEventListener('dragover', allowDrag);
myDrop.addEventListener('dragleave', function(e) {
   hideDropZone();
});
myDrop.addEventListener('drop', handleDrop);
raja
Published on 10-Apr-2018 10:40:10
Advertisements