Skip to content

Instantly share code, notes, and snippets.

@FreeWall
Created July 7, 2020 09:29
Show Gist options
  • Save FreeWall/6705c583a238d63b2e63dedef99f33fb to your computer and use it in GitHub Desktop.
Save FreeWall/6705c583a238d63b2e63dedef99f33fb to your computer and use it in GitHub Desktop.
drag&drop upload example
$(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("");
});
@FreeWall
Copy link
Author

FreeWall commented Sep 4, 2020

<label for='file'>
    <input type='file' name='file' id='file'/>
    <i class='fa fa-upload'></i><span>Nahrát přílohu</span>
</label>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment