I have several dropzones for uploading files to a web page.
How to select all dropzone elements as soon as the file is dragged into the browser so that the user knows where to delete it? And when the file is dragged over one of the dropzones, I need to add an extra class to indicate that the user can free the file
Update
kurideja pointed me in the right direction to dragster
https://github.com/bensmithett/dragster
Now it almost works :)
- If you drag one dropzone and drag it back without releasing the file, all dropzones will be hidden.
http://jsfiddle.net/L7v2f96z/9/
HTML
<div class="dropzone"></div> <div class="dropzone"></div>
Javascript
// Add/remove class when file is dragged over the dropzone. Hover effect $('.dropzone').dragster({ enter : function(){ $(this).show().addClass('hover'); }, leave : function(){ $(this).hide().removeClass('hover'); } }); // Show/hide dropzones until a file is dragged into the browser window. Hide dropzones after file is dropped or dragging is stopped var w = $(window).dragster({ enter : function(){ $('.dropzone').show(); }, leave : function(){ $('.dropzone').hide(); } }) // Prevent defaults (file is openened in the browser) if user drops file outside a dropzone .on('dragover', function(e){ e.preventDefault(); }) .on('drop', function(e){ e.preventDefault(); w.trigger('dragleave'); });
CSS
.dropzone { width:200px; height:200px; background:#fff; display:none; border:2px dashed rgba(0,0,0,0.5); box-shadow:0 2px 5px rgba(0,0,0,0.1), inset 0 0 40px rgba(0,0,0,0.1); border-radius:2px; margin:10px; } .dropzone.hover { background:#e3e3e3; }
javascript jquery
clarkk
source share