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

mouse-event-offset

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

mouse-event-offset

get relative position from an event

  • 3.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
188K
increased by3.15%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 29 Sep 2015

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