Socket
Book a DemoInstallSign in
Socket

@danielgindi/dropzone

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@danielgindi/dropzone

A simple lib for creating styleable dropzones for files

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
16
-62.79%
Maintainers
1
Weekly downloads
 
Created
Source

dropzone.jd

A simple lib for creating styleable dropzones for files

  • Call new DropZone(myElement) to initialize (On any element, event the body)
  • Adds drop-available class to the dropzone element when a file is being dragged to the window. This is useful if you want to style your element to show that it is possible to drop the file on it.
  • Adds drop-over class to the dropzone when the file is being dragged right over it.
  • There is a backwards compatible jQuery plugin available, just npm install jquery.dropzone.

Remember, you need to preventDefault() on the 'drop' event, or the browser will use the default action on the dropped file, which is to download it or redirect to the file.

It's possible to instruct it to add an extra element inside the dropzone when a file is being dragged to the window, which will also receive the drop-over class.
This is useful for creating a dropzone on body, and having a styled dropzone element float above everything else.

This is done by passing an append option:

const myZone = new DropZone(document.body, { append: '<div class="dropzone-inner">' })

Now just listen to 'drop' event and take the file:

const myZone = new DropZone(document.body, {
    // This is optional, to add an internal element that you can style
    append: '<div class="full-drop-zone"><div class="description-wrapper"><div class="description">Release the file here...</div></div></div>',
    
    // This is optional, to selectively allow dropping
    allowDrop: (event) => {
        return dataTransfer.items.length > 0 && dataTransfer.items[0].kind === 'file';
    }
});

document.body.addEventListener('drop', function (event) {
    event.preventDefault();

    // Do something with the files
    console.log(event.originalEvent.dataTransfer.files);
});
.full-drop-zone {
  display: block;
  position: absolute;
  left: 20px;
  top: 20px;
  right: 20px;
  bottom: 20px;
  border: 2px dashed rgba(0,0,0,.3);
  border-radius: 20px;
  text-align: center;
  z-index: 20;
  background: rgba(255,255,255,0.7);
  color: rgba(0,0,0,.3);
  font-size: 20px;

  &.drop-over {
    border-color: rgba(0,0,0,0.5);
    color: rgba(0,0,0,0.5);
  }

  .description-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
  }

  .description {
    position: absolute;
    left: 50%;
    top: 50%;
    max-width: 100%;
    max-height: 100%;
    text-align: center;
    -ms-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
  }
}

Cleanup

myZone.dropzone('destroy');

Me

  • Hi! I am Daniel Cohen Gindi. Or in short- Daniel.
  • danielgindi@gmail.com is my email address.
  • That's all you need to know.

Help

I have invested, and investing, a lot of time in this project. If you want to help, you could:

  • Actually code, and issue pull requests
  • Test the library under different conditions and browsers
  • Create more demo pages
  • Spread the word

Donate

License

All the code here is under MIT license. Which means you could do virtually anything with the code. I will appreciate it very much if you keep an attribution where appropriate.

The MIT License (MIT)

Copyright (c) 2013 Daniel Cohen Gindi (danielgindi@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

FAQs

Package last updated on 17 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.