All Projects → xieziyu → Angular2 Draggable

xieziyu / Angular2 Draggable

Licence: mit
Angular directive (for version >= 2.x ) that makes the DOM element draggable and resizable

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular2 Draggable

Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (-5.19%)
Mutual labels:  angular4, angular6
Angular-Movies
Angular Movies | TV Shows is a simple web app that consumes The Movie DB API - Angular 13 + Material Angular
Stars: ✭ 35 (-87.04%)
Mutual labels:  angular4, angular6
ngx-konami
A simple directive to add easter eggs in your Angular application 👾
Stars: ✭ 34 (-87.41%)
Mutual labels:  angular4, angular6
jsPanel3
A jQuery Plugin to create highly configurable floating panels, modals, tooltips, hints/notifiers or contextmenus for use in a backend solution and other web applications.
Stars: ✭ 89 (-67.04%)
Mutual labels:  draggable, resizable
mean-stack
MEAN stack Mongoose, Express, Angular6, Node
Stars: ✭ 22 (-91.85%)
Mutual labels:  angular4, angular6
react-web-editor
The react-web-editor is a WYSIWYG editor library. you can resize and drag your component. It also has simple rich text editor
Stars: ✭ 191 (-29.26%)
Mutual labels:  draggable, resizable
ngx-image-editor
Awesome image editor for Angular 6
Stars: ✭ 74 (-72.59%)
Mutual labels:  angular4, angular6
ng2-gridstack
A gridstack component for Angular2+
Stars: ✭ 12 (-95.56%)
Mutual labels:  angular4, draggable
vue-smart-widget
🗃️Smart widget is a flexible and extensible content container component for Vue2.x / Vue3.x in Next branch.
Stars: ✭ 110 (-59.26%)
Mutual labels:  draggable, resizable
angular2-cookie-law
Angular2+ component that provides a banner to inform users about cookie law
Stars: ✭ 38 (-85.93%)
Mutual labels:  angular4, angular6
ng-toggle
Bootstrap-styled Angular Toggle Component
Stars: ✭ 14 (-94.81%)
Mutual labels:  angular4, angular6
TNImageView-Android
Android Library for making scale-able and rotatable image views or giving this power to your own image view. This repo has been depreciated.
Stars: ✭ 18 (-93.33%)
Mutual labels:  draggable, resizable
spring-websocket-angular6
Example for using Spring Websocket and Angular with Stomp Messaging
Stars: ✭ 18 (-93.33%)
Mutual labels:  angular4, angular6
ngx-print
🖨️ A plug n' play Angular (2++) library to print your stuff
Stars: ✭ 124 (-54.07%)
Mutual labels:  angular4, angular6
angularx-qrcode-sample-app
Angular5/6/7/8/9/10+ sample apps with working implementations of angularx-qrcode
Stars: ✭ 15 (-94.44%)
Mutual labels:  angular4, angular6
angular-rollbar-source-maps
Angular 2+ implementation to upload sourcemaps to Rollbar
Stars: ✭ 17 (-93.7%)
Mutual labels:  angular4, angular6
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (-88.15%)
Mutual labels:  angular4, angular6
vue-drr
A Vue2 component for draggable, resizable, rotatable elements
Stars: ✭ 34 (-87.41%)
Mutual labels:  draggable, resizable
vue-drag-resize-rotate
一个Vue组件,支持拖拽,拉伸,旋转,放缩,自动对齐;A Vue component that supports dragging, stretching, rotating, scaling, and auto-alignment;
Stars: ✭ 42 (-84.44%)
Mutual labels:  draggable, resizable
angular-progress-bar
This component allow you to easy incorporate progress-bar to angular/ionic project, providing binding and color options
Stars: ✭ 26 (-90.37%)
Mutual labels:  angular4, angular6

angular2-draggable

npm npm Build Status

Table of contents

  1. Getting Started
  2. Latest Update
  3. Installation
  4. Draggable
  5. Resizable
  6. API
  7. Events

Getting Started

angular2-draggable has angular directives that make the DOM element draggable and resizable.

  • ngDraggable

    • v2.x requires Angular >= 6
    • v1.5.0 requires Angular >= 4 && < 6
  • ngResizable

    • provided since v2.0, requires Angular >= 6

Latest Update

  • 2019.08.01: 1.5.0:

    • ngDraggable:
      • Porting features from v2 to v1
  • 2019.06.10: 2.3.2:

  • 2019.05.14: 2.3.0:

    • ngResizable:

      • Fix issue #157: Problem resizing with containment
      • Add direction property in IResizeEvent.
    • ngDraggable:

      • Add CSS class ng-dragging when dragging.

Installation

npm install angular2-draggable --save

Draggable

Please refer to the demo page.

  1. Firstly, import AngularDraggableModule in your app module (or any other proper angular module):

    import { AngularDraggableModule } from 'angular2-draggable';
    
    @NgModule({
      imports: [
        ...,
        AngularDraggableModule
      ],
      ...
    })
    export class AppModule { }
    
  2. Then: use ngDraggable directive to make the DOM element draggable.

    • Simple example:

      • html:
      <div ngDraggable>Drag me!</div>
      
    • Use [handle] to move parent element:

      • html:
      <div ngDraggable [handle]="DemoHandle" class="card">
        <div #DemoHandle class="card-header">I'm handle. Drag me!</div>
        <div class="card-block">You can't drag this block now!</div>
      </div>
      

Resizable

Please refer to the demo page.

Besides of importing AngularDraggableModule, you need to import resizable.min.css in your project. If you use angular-cli, you can add this in angular.json:

"styles": [
    ...
+   "node_modules/angular2-draggable/css/resizable.min.css"
]

Then you can use ngResizable directive to make the element resizable:

<div ngResizable> I'm now resizable </div>

<div [ngResizable]="false"> Resizable is disabled now </div>

<div ngResizable [rzHandles]="'n,e,s,w,se,sw,ne,nw'"> Each side is resizable </div>

Well you can use both directives concurrently if you wish:

<div ngDraggable ngResizable> I'm now draggable and resizable </div>

API

Directive:

  • ngDraggable directive support following input porperties:

    Input Type Default Description
    ngDraggable boolean true You can toggle the draggable capability by setting true or false
    handle HTMLElement null Use template variable to refer to the handle element. Then only the handle element is draggable
    zIndex string null Use it to set z-index property when element is not moving
    zIndexMoving string null Use it to set z-index property when element is moving
    bounds HTMLElemnt null Use it to set the boundary
    inBounds boolean false Use it make element stay in the bounds
    outOfBounds { top: boolean; bottom: boolean; right: boolean; left: boolean } false Set it to allow element get out of bounds from the direction. Refer to demo
    position { x: number, y: number } { x:0, y:0 } Use it to set position offset
    gridSize number 1 Use it for snapping to grid. Refer to demo
    preventDefaultEvent boolean false Whether to prevent default mouse event
    scale number 1 Set it when parent element has CSS transform scale
    lockAxis 'x' | 'y' null Restrict dragging to a specific axis by locking another one
  • ngResizable directive support following input porperties:

    Input Type Default Description
    ngResizable boolean true You can toggle the resizable capability by setting true or false
    rzHandles string "e,s,se" Which handles can be used for resizing. Optional types in "n,e,s,w,se,sw,ne,nw" or "all"
    rzAspectRatio boolean | number false boolean: Whether the element should be constrained to a specific aspect ratio. number: Force the element to maintain a specific aspect ratio during resizing (width/height)
    rzContainment Selector | string | Element null Constrains resizing to within the bounds of the specified element or region. It accepts an HTMLElement, 'parent' or a valid CSS selector string such as '#id'
    rzGrid number | number[] 1 Snaps the resizing element to a grid, every x and y pixels. Array values: [x, y]
    rzMinWidth number 1 The minimum width the resizable should be allowed to resize to.
    rzMaxWidth number 1 The maximum width the resizable should be allowed to resize to.
    rzMinHeight number 1 The minimum height the resizable should be allowed to resize to.
    rzMaxHeight number 1 The maximum height the resizable should be allowed to resize to.
    preventDefaultEvent boolean false Whether to prevent default mouse event.

CSS:

  • When ngDraggable is enabled on some element, ng-draggable and ng-dragging class is automatically toggled on it. You can use it to customize the pointer style. For example:

    .ng-draggable {
      cursor: grab;
    }
    
    .ng-dragging {
      cursor: grabbing;
    }
    
  • When ngResizable is enabled on some element, ng-resizable class is automatically assigned to it. And handle elements will be created with ng-resizable-handle. You can customize the handle style.

Events

  • ngDraggable directive:

    Output $event Description
    started nativeElement of host emitted when start dragging
    stopped nativeElement of host emitted when stop dragging
    edge { top: boolean, right: boolean, bottom: boolean, left: boolean } emitted after [bounds] is set
    movingOffset { x: number, y: number } emit position offset when moving
    endOffset { x: number, y: number } emit position offset when stop moving

    Simple example:

    <div ngDraggable
      (started)="onDragBegin($event)"
      (stopped)="onDragEnd($event)"
      (movingOffset)="onMoving($event)"
      (endOffset)="onMoveEnd($event)">
      Drag me!
    </div>
    
  • ngResizable directive:

    Output $event description
    rzStart IResizeEvent emitted when start resizing
    rzResizing IResizeEvent emitted when resizing
    rzStop IResizeEvent emitted when stop resizing
    export interface IResizeEvent {
      host: any;
      handle: any;
      size: {
        width: number;
        height: number;
      };
      position: {
        top: number;
        left: number;
      };
      direction: {
        n: boolean;
        s: boolean;
        w: boolean;
        e: boolean;
      };
    }
    

    Simple example:

    <div ngResizable
      (rzStart)="onResizeStart($event)"
      (rzResizing)="onResizing($event)"
      (rzStop)="onResizeStop($event)">
      Resizable
    </div>
    

Demo

You can clone this repo to your working copy and then launch the demo page in your local machine:

npm install
npm run demo

# or
yarn install
yarn demo

The demo page server is listening to: http://localhost:4203

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