mouse-event-offset

WebJar for mouse-event-offset

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

mouse-event-offset
Last Version

Last Version

3.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

mouse-event-offset
WebJar for mouse-event-offset
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mattdesl/mouse-event-offset

Download mouse-event-offset

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

mouse-event-offset

stable

Computes the [ offsetX, offsetY ] from a mouse or touch event, relative to the top left of the target element.

var offset = require('mouse-event-offset')

window.addEventListener('touchstart', function (ev) {
  var target = ev.currentTarget
  var touch = ev.changedTouches[0]
  var pos = offset(touch, target)
  //=> [ 128, 52 ]
})

Usage

position = offset(event, [target], [out])

Pass a MouseEvent or TouchEvent as event.

Optionally, you can specify a target element which the touch event should be relative to. Defaults to event.currentTarget, falling back to event.srcElement for older IE.

You can also specifiy out to store the position in that array, and avoid creating a new one.

Changelog

  • 3.x new version; simpler API, less assumptions, avoids GC thrashing
  • 2.x uses ev.currentTarget instead of ev.target
  • 1.x simple implementation using ev.target || ev.srcElement

License

MIT, see LICENSE.md for details.

Versions

Version
3.0.2