All Projects → nichollascarter → subjx

nichollascarter / subjx

Licence: MIT License
Drag/Resize/Rotate Javascript library

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to subjx

Html5sortable
VanillaJS sortable lists and grids using native HTML5 drag and drop API.
Stars: ✭ 1,384 (+792.9%)
Mutual labels:  drag, vanilla-javascript
Vue Drag Resize
Vue Component for resize and drag elements
Stars: ✭ 1,007 (+549.68%)
Mutual labels:  resize, drag
Snap.svg.zpd
A zoom/pan/drag/rotate plugin for Snap.svg (useful for view only)
Stars: ✭ 119 (-23.23%)
Mutual labels:  snap, drag
Medium Zoom
🔎🖼 A JavaScript library for zooming images like Medium
Stars: ✭ 2,799 (+1705.81%)
Mutual labels:  vanilla-javascript, no-dependencies
anim-event
Event Manager for Animation
Stars: ✭ 25 (-83.87%)
Mutual labels:  resize, drag
Any Touch
👋 手势库, 按需2kb~5kb, 兼容PC / 移动端
Stars: ✭ 567 (+265.81%)
Mutual labels:  drag, rotate
Vue Draggable Resizable Gorkys
Vue 用于可调整大小和可拖动元素的组件并支持冲突检测、元素吸附、元素对齐、辅助线
Stars: ✭ 521 (+236.13%)
Mutual labels:  resize, drag
Imaging
Imaging is a simple image processing package for Go
Stars: ✭ 4,023 (+2495.48%)
Mutual labels:  resize, rotate
React Rnd
🖱 A resizable and draggable component for React.
Stars: ✭ 2,560 (+1551.61%)
Mutual labels:  resize, drag
Vue3 Draggable Resizable
[Vue3 组件] 用于拖拽调整位置和大小的的组件,同时支持冲突检测,元素吸附对齐,实时参考线。
Stars: ✭ 159 (+2.58%)
Mutual labels:  resize, drag
Long Press Event
Adds `long-press` event to the DOM in 1k of pure JavaScript
Stars: ✭ 187 (+20.65%)
Mutual labels:  vanilla-javascript, no-dependencies
js-calendar
The lightest Javascript calendar out there, without any dependency.
Stars: ✭ 37 (-76.13%)
Mutual labels:  vanilla-javascript, no-dependencies
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (+4.52%)
Mutual labels:  vanilla-javascript, no-dependencies
Splide
Splide is a lightweight, powerful and flexible slider and carousel, written in pure JavaScript without any dependencies.
Stars: ✭ 786 (+407.1%)
Mutual labels:  drag, vanilla-javascript
Vuegg
🐣 vue GUI generator
Stars: ✭ 2,056 (+1226.45%)
Mutual labels:  resize, drag
reactablejs
A react high-order component for interact.js(drag and drop, resizing and multi-touch gestures).
Stars: ✭ 59 (-61.94%)
Mutual labels:  resize, drag
tabbis.js
Pure vanilla javascript tabs with nesting
Stars: ✭ 44 (-71.61%)
Mutual labels:  vanilla-javascript, no-dependencies
navbuilder
Generiert frei definierbare Navigationsbäume mittels Drag & Drop
Stars: ✭ 21 (-86.45%)
Mutual labels:  drag
Perspective
🖼Parallax scrolling effect. And more.
Stars: ✭ 80 (-48.39%)
Mutual labels:  vanilla-javascript
Blazor.Diagrams
A fully customizable and extensible all-purpose diagrams library for Blazor
Stars: ✭ 327 (+110.97%)
Mutual labels:  drag

Subjx(dragging/resizing/rotating)

Draggable, Resizable, Rotatable library for creating drag-n-drop applications.

Demos

Basic example

Drag, zoom and pan SVG

Usage

Library provides dragging/resizing/rotating/snapping SVG/HTML Elements.

Installation

Run npm install to install with npm.

npm install subjx

Including via a <script> tag:

<script src="../dist/js/subjx.js"></script>

Get started

Main function subjx returns Subjx instance which based on elements finded by passed parameters:

import subjx from 'subjx';
import 'subjx/dist/style/subjx.css';

// possible parameters
const xElem = subjx( 'selector' ) |
                subjx( element ) |
                subjx( elementArray );

Transformation(drag/resize/rotate)

// enabling tool by `drag` method with the optional parameters
// by default just call `.drag()`
const xDraggable = xElem.drag();

// for disabling use `disable` method for each object
xDraggable.disable();

"Draggable" API

// getter returns root DOM element of 'controls'
xDraggable.controls;

// provides access to useful options
xDraggable.storage;
// for example: to get reference to any handle's DOM
const {
  handles: { tl, tr, ...etc }
} = xDraggable.storage;

// enables dragging
// there is no need to call this method manually
xDraggable.enable(options);

// disables dragging, removes controls and handles
xDraggable.disable();

 // adds event listener for some events
xDraggable.on(eventName, cb);

// removes event listener for some events
xDraggable.off(eventName, cb);

// Event names
const EVENTS = [
    'dragStart',
    'drag',
    'dragEnd',
    'resizeStart',
    'resize',
    'resizeEnd',
    'rotateStart',
    'rotate',
    'rotateEnd'
];

// execute dragging manually
xDraggable.exeDrag({
    dx, // drag along the x axis
    dy // drag along the y axis
});

// execute resizing manually
xDraggable.exeResize({
    dx, // resize along the x axis
    dy, // resize along the y axis
    revX, // reverse resizing along the x axis
    revY, // reverse resizing along the y axis
    doW, // allow width resizing
    doH  // allow height resizing
});

// execute rotating manually
xDraggable.exeRotate({
    delta // radians
});

// Align element inside container: ['t', 'l', 'r', 'b', 'v', 'h']
xDraggable.applyAlignment('tr');

// Call this method when applying scale or viewBox values changing
// useful when element's container was transformed from outside
xDraggable.fitControlsToSize();

// Sets the origin for an element's transformations
xDraggable.setTransformOrigin(
    {
        x, // absolute the origin's position x coordinate
        y, // absolute he origin's position y coordinate
        dx, // offset the origin's position x coordinate
        dy // offset the origin's position y coordinate
    },
    pin // leaves current origin fixed if true or not if false
);

// Sets transform origin to default
xDraggable.resetTransformOrigin();

// Returns element's current dimensions
xDraggable.getDimensions();

transformOrigin

Options

Property Description Type Default
container Transformation coordinate system 'selector' | element element.parentNode
controlsContainer "controls" will append to this element 'selector' | element element.parentNode
axis Constrain movement along an axis string: 'x' | 'y' | 'xy' 'xy'
snap Snapping to grid in pixels/radians object { x: 10, y: 10, angle: 10 }
each Mimic behavior with other '.draggable' elements object { move: false, resize: false, rotate: false }
proportions Keep aspect ratio when resizing boolean false
draggable Allow or deny an action boolean true
resizable Allow or deny an action boolean true
rotatable Allow or deny an action boolean true
scalable Applies scaling only to root element boolean false
restrict Restricts element dragging/resizing/rotation 'selector' | element -
rotatorAnchor Rotator anchor direction string: 'n' | 's' | 'w' | 'e' 'e'
rotatorOffset Rotator offset number 50
transformOrigin Sets the origin for an element's transformations boolean | Array false

Notice: In most cases, it is recommended to use 'proportions' option

Methods

subjx('.draggable').drag({
    onInit(elements) {
        // fires on tool activation
    },
    onMove({ clientX, clientY, dx, dy, transform }) {
        // fires on moving
    },
    onResize({ clientX, clientY, dx, dy, transform, width, height }) {
        // fires on resizing
    },
    onRotate({ clientX, clientY, delta, transform }) {
        // fires on rotation
    },
    onDrop({ clientX, clientY }) {
        // fires on drop
    },
    onDestroy(el) {
        // fires on tool deactivation
    }
});

Subscribing new draggable element to previously activated(useful with each option)

const options = {};
const observable = subjx.createObservable();
subjx('.draggable').drag(options, observable);

// pass Observable to new element
const createDraggableAndSubscribe = e => {
    subjx(e.target).drag(options, observable);
};

Allowed SVG elements: g, path, rect, ellipse, line, polyline, polygon, circle

Cloning

Options

const xCloneable = xElem.clone({
    // dropping area
    stack: 'selector',
    // set clone parent
    appendTo: 'selector',
    // set clone additional style
    style: {
        border: '1px dashed green',
        background: 'transparent'
    }
});

Methods

subjx('.cloneable').clone({
    onInit(el) {
        // fires on tool activation
    },
    onMove(dx, dy) {
        // fires on moving
    },
    onDrop(e) {
        // fires on drop
    },
    onDestroy() {
        // fires on tool deactivation
    }
});

Disabling

xCloneable.disable();

License

MIT (c) Karen Sarksyan

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].