Home

Awesome

ngx-draggable-dom

Angular attribute directive that causes any element to become a draggable element.

Table of contents

  1. About This Package
  2. Latest News
  3. Installation
  4. Usage
  5. API

About This Package

This package provides a directive for Angular that makes any DOM element draggable. This project began as a fork of the angular2-draggable directive by xieziyu and was created to provide a more robust set of features and to keep package releases on the bleeding edge. The initial fork was known as ng2-draggable-dom and was deprecated in favor of this package that runs using the latest Angular dependencies and tools for libraries.

Installation

npm install ngx-draggable-dom --save

Usage

  1. Import NgxDraggableDomModule in your app module (or other Angular module) and place it in your imports section:

    import { NgxDraggableDomModule } from "ngx-draggable-dom";
    
    @NgModule({
       imports: [
         ...,
         NgxDraggableDomModule,
       ],
       ...
    })
    export class AppModule { }
    
  2. Use the ngxDraggableDom directive to make a DOM element draggable.

    <div ngxDraggableDom="true">Drag me!</div>
    
  3. Import ngx-draggable-dom.scss to your application's styles or add it to your angular.json if you use the CLI tools.

  4. Explore the API of inputs and outputs to help make your element drag just the way you would like, or run the wrapper project to test it out with some pre-designed examples!

API

Input Properties

ngxDraggableDom {boolean}

handle {HTMLElement}

bounds {HTMLElement}

constrainByBounds {boolean}

requireMouseOver {boolean}

requireMouseOverBounds {boolean}

ignoreMultiTouchEvents {boolean}

Output Emitters

started {NgxDraggableDomMoveEvent}

stopped {NgxDraggableDomMoveEvent}

moved {NgxDraggableDomMoveEvent}

edge {NgxDraggableDomBoundsCheckEvent}

Events

NgxDraggableDomMoveEvent

NgxDraggableDomBoundsCheckEvent

Public Functions

reset() {void}

CSS

When ngxDraggableDom is enabled on some element, the ngx-draggable class is automatically assigned to it. When the user is actively dragging the element, the class ngx-dragging is applied to the element (or the specified handle). If you include the provided ngx-draggable-dom.scss styles into your project from node_modules/ngx-draggable-dom/styles/ngx-draggable-dom.scss, you will receive native styling and support for turning off CSS transitions while interacting with the element. You can override these to customize the look and feel for when you are interacting with the element. For example, change the cursor style for draggable elements in your page by doing the following:

.ngx-draggable {
  cursor: move;
}

.ngx-dragging {
  cursor: grabbing !important;
}