Dragdrop

A JavaScript micro-framework for adding drag-and-drop functionality to elements for advanced UI development

View the Project on GitHub kbjr/DragDrop

View Demo

License

Copyright 2012 James Brumond
Dual licensed under MIT and GPL

Features

Samples! :)

// Make myElement drag-and-drop enabled
DragDrop.bind(myElement);

// A more complex version
var draggable = DragDrop.bind(myElement, {
    // The anchor; myElement moves when anotherElement is dragged
    anchor: anotherElement,
    // The draggable element will now stay bound within it's offsetParent
    boundingBox: 'offsetParent',
    // Define a dragstart event
    dragstart: function(evt) {
        // ...
    }
});

// Change the bounding box to some manual positions
draggable.setBoundingBox({
    x: { min: 0, max: 600 },
    y: { min: 0, max: 400 }
});

// Define a new dragend event
draggable.bindEvent('dragend', function(evt) {
    // ...
});

// This is how you would remove a drag event (if one were defined above)
draggable.unbindEvent('drag', theBoundDragEventFunction);