Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/mouse-event
Cross browser mouse event property access
https://github.com/mikolalysenko/mouse-event
Last synced: about 2 months ago
JSON representation
Cross browser mouse event property access
- Host: GitHub
- URL: https://github.com/mikolalysenko/mouse-event
- Owner: mikolalysenko
- License: mit
- Created: 2015-02-16T22:36:45.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-26T01:27:18.000Z (over 9 years ago)
- Last Synced: 2024-10-20T14:28:02.604Z (2 months ago)
- Language: JavaScript
- Homepage: https://mikolalysenko.github.io/mouse-event
- Size: 164 KB
- Stars: 28
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mouse-event
Provides a normalized, cross-browser, garbage-collection-free API for reading out the state of a mouse event.### Why is this needed?
Because it is 2015 and somehow every major browser still disagrees on even the most basic details of MouseEvents. Seriously guys.# Example
```javascript
var mouse = require('mouse-event')window.addEventListener('mousemove', function(ev) {
document.body.innerHTML =
'Buttons: ' + mouse.buttons(ev) +
'
' x:' + mouse.x(ev) +
' y:' + mouse.y(ev) + '
})
```[Try this in your browser](https://mikolalysenko.github.io/mouse-event)
# Install
```
npm i mouse-event
```# API
```javascript
var mouse = require('mouse-event')
```#### `mouse.buttons(event)`
Returns a bit vector, similar to `event.which` in WebKit encoding the state of the mouse buttons.* `event` is a mouse event
**Returns** A bit vector with the following interpretation for the flags:
* `1` - left mouse
* `2` - right mouse
* `4` - middle mouse
* `8` - button 4
* `16` - button 5
* ...
* `1<