JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 306912
  • Score
    100M100P100Q179243F
  • License MIT

get relative position from an event

Package Exports

  • mouse-event-offset

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mouse-event-offset) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mouse-event-offset

experimental

Gets the offsetX/offsetY from a mouse event, relative to the top left of the target (i.e. clicked) element. This uses currentTarget (i.e. the element that you specified for the event) and falls back to srcElement.

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

events.on(element, 'click', function(e) {
    var pos = offset(e)
    console.log(pos.x, pos.y)
})

Usage

NPM

offset(event[, options])

Pass an event object to the function, and a position with { x, y } is returned. The options:

  • clientRect is a pre-computed bounding client rect or offset (e.g. to avoid reflows), defaults to use the target's getBoundingClientRect() (or offset (0, 0) in the case of window/body)
  • clientX is the client x position, defaults to event.clientX
  • clientY is the client y position, defaults to event.clientY

License

MIT, see LICENSE.md for details.