Created
May 24, 2017 11:08
-
-
Save Krasnov8953/5c4f4cdc829537ed6c42f74130835240 to your computer and use it in GitHub Desktop.
drag and drop files to input type file
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).ready(function(){ | |
$('body').on('dragenter', function(){ | |
$('input[type="file"]').addClass('drag'); | |
console.log('enter'); | |
}); | |
$('input[type="file"]').on('dragleave', function(e){ | |
e.stopPropagation(); | |
$('input[type="file"]').removeClass('drag'); | |
console.log('leave'); | |
}); | |
$('body').on('drop',function(){ | |
$('input[type="file"]').removeClass('drag'); | |
$('input[type="file"]').on('change', function (event, files, label) { | |
var file_name = this.value.replace(/\\/g, '/').replace(/.*\//, '') | |
$('.filename').text(file_name); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment