Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wildebeest/drag

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wildebeest/drag

Draging event module

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Drag Module

Add drag event to DOM elements. Drag event is triggered when user moves the mouse, while holding down left mouse button.

Installation

npm install --save @wildebeest/drag

Requirements

It's usefull to know these libraries:

  • inversify
  • @wildebeest/js-modules

Bind Element To Dragable Component

Making element to emit wbDrag and wbDragended events, requires creating new instance of class DragableComponent.

foo(emitterService: EmitterService): void
{
    let element: any = document.querySelector('.dragable');
    let dragable: DragableComponent = new DragableComponent(element, emitterService.createEmitter());
}

In our example we used .dragable selector to select DOM element and then create DragableComponent, that will listen to specific changes on this element. If it finds a drag, it will emit drag event.

Listen To Drag Event

Drag event is called wbDrag and the event contains three values horizontal and vertical movement difference after last movement. mouseEvent, which is the original MouseEvent.

foo(emitterService: EmitterService): void
{
    let element: any = document.querySelector('.dragable');
    let dragable: DragableComponent = new DragableComponent(element, emitterService.createEmitter());

    dragable.getEmitter().on('wbDrag' (data: any) => {
        let verticalMovement: number = data.vertical;
        let horizontalMovement: number = data.horizontal;
        let originalEvent: MouseEvent = data.mouseEvent;
    });
}

Listen To Dragended Event

Dragended event is called wbDrag and the event contains three values horizontal and vertical movement difference after last movement. In this case, those values will be 0. And mouseEvent, which is the original MouseEvent.

foo(emitterService: EmitterService): void
{
    let element: any = document.querySelector('.dragable');
    let dragable: DragableComponent = new DragableComponent(element, emitterService.createEmitter());

    dragable.getEmitter().on('wbDragended' (data: any) => {
        let verticalMovement: number = data.vertical;
        let horizontalMovement: number = data.horizontal;
        let originalEvent: MouseEvent = data.mouseEvent;
    });
}

Keywords

FAQs

Package last updated on 22 Apr 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc