Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twotau/mouse.js
A very small JavaScript library that allows you to track a client's cursor position on an element
https://github.com/twotau/mouse.js
Last synced: 14 days ago
JSON representation
A very small JavaScript library that allows you to track a client's cursor position on an element
- Host: GitHub
- URL: https://github.com/twotau/mouse.js
- Owner: TwoTau
- Created: 2015-09-22T23:54:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-20T03:54:29.000Z (about 9 years ago)
- Last Synced: 2023-02-27T18:25:47.134Z (over 1 year ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MouseJS
A very small JavaScript library that allows you to track a client's cursor position on an elementYou can download ```Mouse.js``` and add it to your HTML:
```html```
Next, initialize it with a line of JavaScript:
```javascript
var mouse = new MouseJS(someElement);
```
You can find
* Where the user's mouse position with `mouse.x``` and ```mouse.y`
* Where the user last left clicked with `mouse.left.before.x`
* When the user last pressed down their left mouse button with `mouse.left.clickTime`
* When the user last released their left mouse button with `mouse.left.releaseTime`
* And the same for the right mouse buttonAll MouseJS times are formatted in milliseconds since the object's initialization. For example:
```js
console.log(mouse.right.clickTime); // might be something like 1250 (for 1.25 seconds)
```You can tell if the client's left mouse button is down with:
```js
console.log(mouse.left.releaseTime < mouse.getTime())
```Note that the HTML element has to have `focus` for MouseJS to be able to track the client's mouse. You can force an element to have focus with
```js
someElement.focus();
```