Socket
Socket
Sign inDemoInstall

mouse-pos

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouse-pos

A simple and lightweight lib to get cross-browser mouse events


Version published
Maintainers
1
Weekly downloads
1,173
decreased by-48.12%

Weekly downloads

Readme

Source

mouse-pos

A super simple cross-browser library to get the correct coordinates of your mouse event. Just pass the method the event obj and it will return the distance you need (as array).

npm install mouse-pos

use it like this

var mouse = require("mouse-pos");
var el = document.getElementById("outside");
el.addEventListener("click", function(e){
console.log("rel coords", mouse.getRel(e)); // e.g. [5,5]
console.log("abs coords", mouse.getAbs(e)); // e.g. [205,205]
});
rel(e) - relative to the target

[x,y]

abs(e) - absolute to the screen

[x,y]

wheelDelta(e)

float of pixels the mouse wheel moved. Could be negative.

Enjoy!

Keywords

FAQs

Last updated on 21 Feb 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc