Lean & Mean Drag and Drop is a small script for dragging, dropping, sorting and reordering html structures

Features
Supports nested structures ('nestable sortables')
Smooth transitions
Auto scroll while dragging
Lightweight (~3.5kb gzipped)
No dependencies
Super easy to integrate with your own app
Supports touch events
Compatible with all modern browsers
Can work with any type of layout
Usage
//Load LMDD css and js files
<link href="../css/lmdd.min.css" rel="stylesheet">
<script src="../js/lmdd.min.js"></script>

//Initialize LMDD instance with your preferred options
<script>lmdd.set(document.getElementById('markupID'),{optionsObject});</script>
Examples
  • speaker_notes
  • filter_1Simple Grid
    Green
    Pink
    Purple
    Blue
    Lime
    Teal
    Amber
    Orange
    Black
  • filter_2Multiple containers + handle
  • filter_3Nested Grid
  • code
Options
  • speaker_notes
    Option Description
    containerClass Containers act as drop zones for draggable items
    draggableItemClass Draggable items can be moved inside and between containers
    handleClass Restricts drag start to a specific element which acts as a drag "handle"
    dragstartTimeout Delays the drag start for a short time to distinct it from other user intentions (such as selecting text)
    calcInterval Time interval in which LMDD evaluates the dragged element position, Short interval means more responsive experience (and more CPU usage)
    revert When set to true the draggable item will revert to its original position when the cursor is out of the container bounds
    nativeScroll LMDD uses its own auto-scroll function, you can eliminate it and use the native browser scroll
    mirrorMinHeight, mirrorMaxWidth Scale down the mirror size when it exceeds the maximum width set
    positionDelay When set to true - position will not be recalculated when the mouse stops moving (Prevents flickering on deep nested structures)
    dataMode When set to 'true' LMDD will undo all DOM mutations when the drag event ends, This is useful for integrating LMDD with Angular/React/Vue etc.
  • code
Advanced
  • content_copyCloning

    To clone dragged elements, just add two additional classes to your markup:
    'lmdd-clonner' - for every element you want to clone when dragged
    'lmdd-dispatcher' - for the container (parent of the elements to be cloned)
    containers having the 'lmdd-dispatcher' class will not act as drop zones, the cloning operation will begin when the mouse cursor enters a different container.

       //Example markup:
        <div id="clone-example"> (scope)
            <div class="grid lmdd-dispatcher"> (dragging items out from this container will clone them)
                <div class="item lmdd-clonner">(this draggable item will be cloned when dragged)
                </div>
            </div>
            <div class="grid"> (container)
            </div>
        </div>
                
  • eventEvents
  • blockRendering Blocks
Integration
  • bookmarkGuidelines

    LMDD is fairly easy to integrate with any other script. I would recommend treating the drag operation as any other user input, think of it as some kind of a sophisticated mouse gesture. Having this point of view in mind, the integration process should be as follows:

    1. Upon rendering your markup, set an LMDD instance on the relevant part of the DOM
    2. Set the dataMode to 'true'. (Which will undo any changes LMDD made on the DOM when the drag operation ends)
    3. Add an eventListener for the 'lmddend' event
    4. Use an event handler to process the event details and implement the necessary changes on your app data/state

  • filter_1Vue Example
  • code
Angular and React integration is pretty much the same, examples will be added to this section later on.
More

Bug reports & feature requests are more than welcome.
Feel free to ask questions and contribute on github

If you are interested in a drag&drop functionality for your web apps, you might also like:

Discussion