desandro/draggabilly là một trong những repo mã nguồn mở mà TopGit theo dõi, hiện có 3.9k sao, viết chủ yếu bằng JavaScript. :point_down: Make that shiz draggable
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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({...})
desandro/draggabilly có 3.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/desandro/draggabilly. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
desandro/draggabilly có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho desandro/draggabilly. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
desandro/draggabilly còn đang phát triển không?
Commit gần nhất trên desandro/draggabilly là 4.4 năm trước (theo timestamp GitHub). Repo có 377 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
desandro/draggabilly viết bằng ngôn ngữ gì?
desandro/draggabilly chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về desandro/draggabilly ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/desandro/draggabilly là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
draggabilly có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về draggabilly.