Socket
Book a DemoInstallSign in
Socket

mouse-pos

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouse-pos

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

1.0.1
Source
npmnpm
Version published
Maintainers
1
Created
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]
});

getRel(e) - relative to the target

[x,y]

getAbs(e) - absolute to the screen

[x,y]

getWheelDelta(e)

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

Enjoy!

Keywords

mouse

FAQs

Package last updated on 26 Sep 2014

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.