All Projects → mystroken → drag

mystroken / drag

Licence: MIT license
🏄 A lightweight JavaScript "hold and drag" utility. Vanilla JS - No dependencies.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to drag

Splide
Splide is a lightweight, powerful and flexible slider and carousel, written in pure JavaScript without any dependencies.
Stars: ✭ 786 (+1817.07%)
Mutual labels:  slider, drag
angular-simple-slider
An AngularJS directive providing a simple slider functionality
Stars: ✭ 15 (-63.41%)
Mutual labels:  slider
RDGliderViewController
Control for a floating view gliding over a ViewController
Stars: ✭ 31 (-24.39%)
Mutual labels:  slider
openap
Open Aircraft Performance Model and Python Toolkit
Stars: ✭ 68 (+65.85%)
Mutual labels:  drag
solid-dnd
A lightweight, performant, extensible drag and drop toolkit for Solid JS.
Stars: ✭ 251 (+512.2%)
Mutual labels:  drag
draggable-polyfill
🌈a beautify polyfill for native drag!
Stars: ✭ 49 (+19.51%)
Mutual labels:  drag
MVideo
An imitation of WeChat circle of friends video effects, can drag and zoom ,video view,base on ijkplayer.
Stars: ✭ 179 (+336.59%)
Mutual labels:  drag
DragPanel
A nice vertical drag layout, a bit like BottomSheet, but with strong customization!
Stars: ✭ 21 (-48.78%)
Mutual labels:  drag
vue-active-swiper
🌴 A Mobile-oriented、No dependencies、Lightweight Swiper component for Vue
Stars: ✭ 33 (-19.51%)
Mutual labels:  slider
VueForm
vue和nodejs实现自定义表单拖拽系统
Stars: ✭ 40 (-2.44%)
Mutual labels:  drag
vue-drag-select
基于Vue的仿原生操作系统鼠标拖拽选择
Stars: ✭ 63 (+53.66%)
Mutual labels:  drag
MaTiSSe
Markdown To Impressive Scientific Slides
Stars: ✭ 43 (+4.88%)
Mutual labels:  slider
KJCircularSlider
Slide circularly. Soon more extended version about to come!
Stars: ✭ 23 (-43.9%)
Mutual labels:  slider
vue3-carousel
Vue 3 carousel component
Stars: ✭ 379 (+824.39%)
Mutual labels:  slider
anim-event
Event Manager for Animation
Stars: ✭ 25 (-39.02%)
Mutual labels:  drag
Flutter slider drawer
You can make slider drawer type ui by this plugin
Stars: ✭ 152 (+270.73%)
Mutual labels:  slider
vue-dialog
A drag-able dialog for Vue.js
Stars: ✭ 21 (-48.78%)
Mutual labels:  drag
vue2-data-tree
A tree that data is lazy loaded. Support dragging node, checking node, editing node's name and selecting node.
Stars: ✭ 41 (+0%)
Mutual labels:  drag
yii2-menu
Menu menager, dynamic Yii2 widget. Active menu items
Stars: ✭ 26 (-36.59%)
Mutual labels:  drag
DragDropUI
A set of iOS UI components which have drag & drop capability.
Stars: ✭ 30 (-26.83%)
Mutual labels:  drag

🏄 drag

npm bundle size npm npm GitHub last commit contributions welcome GitHub stars Tweet

A lightweight JavaScript "hold and drag" utility. Vanilla JS - No dependencies.
Its size is ~867 Bytes (minified and compressed).

See the online demo (Advanced example) | Demo Source Code🔥🔥



Usage

npm install @mystroken/drag and start using the hold and drag system.

import Drag from '@mystroken/drag';

// Elements to listen/move.
const slidable = document.querySelector('#slidable');
const container = document.querySelector('#container');

// Where to store the drag position.
let currentX = 0;
let currentY = 0;

// Initialize the library.
const options = {
  listener: container,
  multiplier: 2
};
const drag = new Drag(options);

// Store the cursor position on move.
drag.on(event => {
  currentX = event.X;
  currentY = event.Y;
});

// Use the cursor position to slide the slidable element.
requestAnimationFrame(move);
function move() {
  slidable.style.transform = `translate3d(${currentX}px, ${currentY}px, 0px)`;
  requestAnimationFrame(move);
}


Options

listener

Determines the DOM element on which to apply the hold and drag feature.

Default Type
window DOM Element

multiplier

Set a speed multiplier for the movement (the normal speed is 1).

Default Type
1 int


Methods

on(callback)

Subscribes a callback function to listen any "hold and drag" operation.

drag.on(function(event) {
  // Start consuming the event data.
  currentX = event.X;
  currentY = event.Y;
});
Argument Type Params Required
callback Function An event object giving the current X & Y positions of the mouse on the container Yes

off(callback)

Unsubscribes the callback function from listening operations.

Argument Type Params Required
callback Function An event object giving the current X & Y positions of the mouse on the container Yes
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].