Created
July 7, 2020 09:29
-
-
Save FreeWall/6705c583a238d63b2e63dedef99f33fb to your computer and use it in GitHub Desktop.
drag&drop upload example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on("dragover drop", function (e) { | |
e.preventDefault(); | |
}); | |
$(".filestorage div.storage").on("dragover drop", function (e) { | |
e.preventDefault(); | |
}).on('dragover dragenter', function() { | |
$(this).addClass('is-dragover'); | |
}).on('dragleave dragend drop', function() { | |
$(this).removeClass('is-dragover'); | |
}).on('drop', function(e) { | |
if (typeof e.originalEvent.dataTransfer != "undefined") { | |
droppedFiles = e.originalEvent.dataTransfer.files; | |
$.each(droppedFiles, function(i, file) { | |
console.log(file); | |
//TODO: add new element with file | |
}); | |
} | |
}); | |
$(".filestorage input#file").change(function (event) { | |
$.each(event.target.files, function(i, file) { | |
console.log(file); | |
//TODO: add new element with file | |
}); | |
$(this).val(""); | |
}); |
Author
FreeWall
commented
Sep 4, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment