desandro/draggabilly sits at 3.9k stars on GitHub, written primarily in JavaScript. :point_down: Make that shiz draggable
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
var $draggable = $('.draggable').draggabilly({
// options...
})
Initialize Draggabilly with vanilla JS
var elem = document.querySelector('.draggable');
var draggie = new Draggabilly( elem, {
// options...
});
// or pass in selector string as first argument
var draggie = new Draggabilly( '.draggable', {
// options...
});
// if you have multiple .draggable elements
// get all draggie elements
var draggableElems = document.querySelectorAll('.draggable');
// array of Draggabillies
var draggies = []
// init Draggabillies
for ( var i=0; i < draggableElems.length; i++ ) {
var draggableElem = draggableElems[i];
var draggie = new Draggabilly( draggableElem, {
// options...
});
draggies.push( draggie );
}
Classes
.is-pointer-down added when the user's pointer (mouse, touch, pointer) first presses down.
.is-dragging added when elements starts to drag.
Options
axis
Type:String
Values:'x' or 'y'
axis: 'x'
Constrains movement to horizontal or vertical axis.
containment
Type:Element, Selector String, or Boolean
containment: '.container'
Contains movement to the bounds of the element. If true, the container will be the parent element.
grid
Type:Array
Values:[ x, y ]
grid: [ 20, 20 ]
Snaps the element to a grid, every x and y pixels.
handle
Type: Selector String, Array, HTMLElement
// select all .handle children with selector string
handle: '.handle'
// set as element
handle: element.querySelector('.handle')
// set as array or NodeList
handle: [ element.querySelector('.handle1'), element.querySelector('.handle2') ]
Specifies on what element the drag interaction starts.
handle is useful for when you do not want all inner elements to be used for dragging, like inputs and forms. See back handle example on CodePen.
Events
Bind events with jQuery with standard jQuery event methods .on(), .off(), and .one(). Inside jQuery event listeners this refers to the Draggabilly element.
// jQuery
function listener(/* parameters */) {
// get Draggabilly instance
var draggie = $(this).data('draggabilly');
console.log( 'eventName happened', draggie.position.x, draggie.position.y );
}
// bind event listener
$draggable.on( 'eventName', listener );
// unbind event listener
$draggable.off( 'eventName', listener );
// bind event listener to trigger once. note ONE not ON
$draggable.one( 'eventName', function() {
console.log('eventName happened just once');
});
Bind events with vanilla JS with .on(), .off(), and .once() methods. Inside vanilla JS event listeners this refers to the Draggabilly instance.
// vanilla JS
function listener(/* parameters */) {
console.log( 'eventName happened', this.position.x, this.position.y );
}
// bind event listener
draggie.on( 'eventName', listener );
// unbind event listener
draggie.off( 'eventName', listener );
// bind event listener to trigger once. note ONCE not ONE or ON
draggie.once( 'eventName', function() {
console.log('eventName happened just once');
});
dragStart
Triggered when dragging starts and the element starts moving. Dragging starts after the user's pointer has moved a couple pixels to allow for clicks.
event - Type:Event - the original mouseup or touchend event
pointer - Type:MouseEvent or Touch - the event object that has .pageX and .pageY
staticClick
Triggered when the user's pointer is pressed and unpressed and has not moved enough to start dragging.
click events are hard to detect with draggable UI, as they are triggered whenever a user drags. Draggabilly's staticClick event resolves this, as it is triggered when the user has not dragged.
Get the Draggabilly instance from a jQuery object. Draggabilly instances are useful to access Draggabilly properties.
var draggie = $('.draggable').data('draggabilly')
// access Draggabilly properties
console.log( 'draggie at ' + draggie.position.x + ', ' + draggie.position.y )
Properties
position
draggie.position
// => { x: 20, y: -30 }
position - Type:Object
x - Type:Number
y - Type:Number
Webpack & Browserify
Install Draggabilly with npm.
npm install draggabilly
var Draggabilly = require('draggabilly');
var draggie = new Draggabilly( '.draggable', {
// options
});
To use Draggabilly as a jQuery plugin, you need to install and call jQuery Bridget.
npm install jquery-bridget
var $ = require('jquery');
var jQueryBridget = require('jquery-bridget');
var Draggabilly = require('draggabilly');
// make Draggabilly a jQuery plugin
jQueryBridget( 'draggabilly', Draggabilly, $ );
// now you can use $().draggabilly()
$('.draggable').draggabilly({...})
TopGit's last sync did not record any GitHub topics for desandro/draggabilly. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on desandro/draggabilly?
The most recent commit recorded on desandro/draggabilly was 4.4 years ago, based on the GitHub push timestamp. The repository has 377 forks — one of the better signals of community interest.
How many stars does desandro/draggabilly have?
desandro/draggabilly has 3.9k GitHub stars — refresh the page for the live number, or check github.com/desandro/draggabilly. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is desandro/draggabilly written in?
desandro/draggabilly is written primarily in JavaScript. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about desandro/draggabilly?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/desandro/draggabilly is the definitive source.
Read full README in the tab above.
Curious whether draggabilly is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about draggabilly.