Created
June 8, 2012 11:49
-
-
Save d33pfri3d/2895218 to your computer and use it in GitHub Desktop.
Drag and Drop
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
var root = document.documentElement; | |
root.addEventListener('dragover', cancel, false); | |
root.addEventListener('dragend', cancel, false); | |
root.addEventListener('drop', drop, false); | |
function cancel(event){ | |
event.preventDefault(); | |
} | |
function drop(event){ | |
cancel(event); | |
readFiles(event.dataTransfer.files); | |
} | |
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
function drop(event){ | |
event.preventDefault(); | |
readFiles(event.dataTransfer.files); | |
} | |
var root = document.documentElement; // Attaching to the HTML document (can be anywhere) | |
root.addEventListener('dragover', function(event){ | |
event.preventDefault(); | |
//bind drop event | |
root.addEventListener('drop', drop, false); | |
}, false); | |
root.addEventListener('dragend', function(){ | |
event.preventDefault(); | |
//bind drop | |
root.removeEventListener('drop', drop, false) | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment