drag-event-service

WebJar for drag-event-service

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

drag-event-service
Last Version

Last Version

1.1.7
Release Date

Release Date

Type

Type

jar
Description

Description

drag-event-service
WebJar for drag-event-service
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/phphe/drag-event-service

Download drag-event-service

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/drag-event-service/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>drag-event-service</artifactId>
    <version>1.1.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/drag-event-service/
implementation 'org.webjars.npm:drag-event-service:1.1.7'
// https://jarcasting.com/artifacts/org.webjars.npm/drag-event-service/
implementation ("org.webjars.npm:drag-event-service:1.1.7")
'org.webjars.npm:drag-event-service:jar:1.1.7'
<dependency org="org.webjars.npm" name="drag-event-service" rev="1.1.7">
  <artifact name="drag-event-service" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='drag-event-service', version='1.1.7')
)
libraryDependencies += "org.webjars.npm" % "drag-event-service" % "1.1.7"
[org.webjars.npm/drag-event-service "1.1.7"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : babel__runtime jar [7.7.7,8)
org.webjars.npm : helper-js jar [2.0.0,3)

Project Modules

There are no modules declared in this project.

drag-event-service

Listen both mouse and touch event. With Typescript definition files. Support Typescript.

同时监听鼠标和触摸事件. 支持Typescript.

// mapping
const events = {
  start: ['mousedown', 'touchstart'],
  move: ['mousemove', 'touchmove'],
  end: ['mouseup', 'touchend'],
}

install

npm install drag-event-service --save

usage & api

import DragEventService from 'drag-event-service'
DragEventService.on(el, name, handler, {args, mouseArgs, touchArgs})
DragEventService.off(el, name, handler, {args, mouseArgs, touchArgs})
  • args, mouseArgs and touchArgs should be Array
  • The args will pass to addEventListener.
  • mouseArgs will pass to mouse event.
  • touchArgs will pass to touch event.
  • handler(event, currentPosition). The second argument of handler is current position({x, y, pageX, pageY, clientX, clientY, screenX, screenY}). x and y is pageX and pageY.

example

// 1
DragEventService.on(document, 'start', (e, mouse) => ..., {touchArgs: [{passive: false}]})
DragEventService.on(document, 'move', (e, mouse) => ..., {touchArgs: [{passive: false}]})
DragEventService.on(document, 'end', (e, mouse) => ..., {touchArgs: [{passive: false}]})
// 2
const handler = (e, mouse) => ...
DragEventService.on(document, 'start', handler)
DragEventService.off(document, 'start', handler)

Track mouse or touch position globally

全局跟踪鼠标或触摸位置

Usage

import {trackMouseOrTouchPosition} from 'drag-event-service'
const {info, start, stop} = trackMouseOrTouchPosition(options)
start() // call start to start tracking.

Types

// options
export interface Options_trackMouseOrTouchPosition{
  onMove: () => void
  onStart: () => void
  onEnd: () => void
}
// info
export interface TrackedInfo{
  position: EventPosition
  event: MouseOrTouchEvent
  eventType: EventType
  isTouch: boolean
  started: boolean
  startEvent?: MouseOrTouchEvent
  endEvent?: MouseOrTouchEvent
}
// 
start: () => void
stop: () => void

Versions

Version
1.1.7