https://github.com/exelban/cursor-position
Simple module for getting click/touch position in element or window.
https://github.com/exelban/cursor-position
browser cursor detect div get mobile module mouse movement pointer position touch wev window
Last synced: about 1 month ago
JSON representation
Simple module for getting click/touch position in element or window.
- Host: GitHub
- URL: https://github.com/exelban/cursor-position
- Owner: exelban
- License: apache-2.0
- Created: 2018-06-14T21:43:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-16T18:10:20.000Z (about 7 years ago)
- Last Synced: 2025-10-02T06:53:13.287Z (6 months ago)
- Topics: browser, cursor, detect, div, get, mobile, module, mouse, movement, pointer, position, touch, wev, window
- Language: TypeScript
- Homepage:
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cursor-position
[](http://www.npmjs.com/package/cursor-position)
[](https://exelban.github.io/cursor-position)
Simple module for getting click/touch position in element or window.
## Install
```sh
yarn add cursor-position
```
Or with npm:
```sh
npm install cursor-position --save
```
## Usage
Library has only one function: ```GetCursorPosition(options)```
```js
import GetCursorPosition from 'cursor-position'
document.setEventListener('mousemove', () => {
const {x, y} = GetCursorPosition()
console.log(x, y)
})
```
### Options
```
{
event?: MouseEvent | TouchEvent
absolute?: boolean
scroll?: boolean
}
```
**Name** | **Type** | **Required** | **Default** | **Description**
--- | --- | --- | --- | ---
**event** | MouseEvent TouchEvent | No | window.event | Click event
**absolute** | Boolean | No | true | Determine if position must be calculated from body or from parent element
**scroll** | Boolean | No | false | Determine if position must include scroll value
### Response
```
{
x number
y number
}
```
## What's new
### v1.0.1
- package.json fixed
### v1.0.0 (BREAKING CHANGES)
- rewrited library in typescript
- removed eslint
- removed @flow
- changed options
- added some tests (in progress)
### v0.0.3
- first release
## License
[Apache License 2.0](https://github.com/exelban/cursor-position/blob/master/LICENSE)