Socket
Socket
Sign inDemoInstall

ng2-draggable-dom

Package Overview
Dependencies
6
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ng2-draggable-dom

## Table of contents 1. [About This Package](#about-this-package) 2. [Latest News](#latest-news) 3. [Installation](#installation) 4. [Usage](#usage) 5. [API](#api)


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
101 kB
Created
Weekly downloads
 

Readme

Source

ng2-draggable-dom npm version npm downloads

Table of contents

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

About This Package

ng2-draggable-dom is a directive for Angular 2+ that makes any DOM element draggable. This project is a fork of the original 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.

Latest News

Always check the CHANGELOG for what's brand new and for all the gooey details! See the top of this readme to see what the current version of this module is.

2017.12.13:

  • Critical bug fixes and enhancements have been made for full bounds constrain support.

2017.12.12:

  • The fork was renamed ng2-draggable-dom to be published as a new npm package.
  • Critical bug fixes and enhancements have been made.

Installation

npm install ng2-draggable-dom --save

Usage

  1. Import DraggableDomModule in your app module (or other proper angular module) and place it in your imports section:

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

    <div ngDraggable>Drag me!</div>
    
  3. Explore the API of inputs and outputs to help make your element drag just the way you would like!

API

Inputs

ngDraggable {boolean}

  • true: the element can be dragged.
  • false: the element cannot be dragged.

handle {HTMLElement}

  • {HTMLElement}: The element that should be used as the selectable region to drag.

bounds {HTMLElement}

  • {HTMLElement}: The element that represents the region the entire draggable element should be kept within. Note, by setting this property you are not forcing it to be constrained within the bounds.

constrainByBounds {boolean}

  • true: if bounds is set, the draggable element will be constrained by that HTMLElement.
  • false (default): if bounds is set, the draggable element will just report which boundary edge has been passed by in the edge output emitter.

Outputs

started {target: nativeElement, position: IPosition} as {IMoveEvent} (exported interface):

  • Emits the nativeElement that is being dragged in $event.target.
  • Emits the current translation in $event.position as an IPosition {x, y}.

stopped {target: nativeElement, position: IPosition} as {IMoveEvent} (exported interface):

  • Emits the nativeElement that is being dragged in $event.target.
  • Emits the current translation in $event.position as an IPosition {x, y}.

moved {target: nativeElement, position: IPosition} as {IMoveEvent} (exported interface):

  • Emits the nativeElement that is being dragged in $event.target.
  • Emits the current translation in $event.position as an IPosition {x, y}.

edge {top: boolean, right: boolean, bottom: boolean, left: boolean} as IBounds (exported interface):

  • if bounds is set, this output will emit an object defining the state of constraint for each edge of the HTMLElement defined by bounds. If the draggable element has just been dragged onto or beyond the right edge of the bounds HTMLElement, you will get an output like the following:
{
  top: true,
  right: false,
  bottom: true,
  left: true,
}
CSS:

When ngDraggable is enabled on some element, the ng-draggable class is automatically assigned to it. You can use it to customize it. For example, change the cursor style for draggable elements in your page by doing the following:

.ng-draggable {
  cursor: move;
}

Keywords

FAQs

Last updated on 13 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc