Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const dropArea = window;
const preventDefaults = (e)=> {
e.preventDefault()
e.stopPropagation();
}
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
})
const handleDrop = (e) => {
let dt = e.dataTransfer
let files = dt.files;
const file = files[0]
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onloadend = () => {
let img = document.createElement('img')
img.onload = () => {
console.log('Image loaded');
}
img.src = reader.result;
}
}
dropArea.addEventListener('drop', handleDrop, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment