-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.next.js
More file actions
33 lines (31 loc) · 843 Bytes
/
index.next.js
File metadata and controls
33 lines (31 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Normalize the pointer events to get a single position of the pointer on the screen
* @param { Object } event - event object
* @returns { Object } position - pointer position on the screen
* @returns { number } position.x - x condinates relative to the screen
* @returns { number } position.y - y condinates relative to the screen
*
* @example
*
* import { position } from 'bianco.pointer'
* import { add } from 'bianco.events'
*
*
* add(window, 'touchmove mousemove', function(event) {
* const { x, y } = position(event)
*
* console.log('Your pointer y is=', y, 'your pointer x is', x)
* })
*
*/
export function position(event) {
// normalize the pointer events
const e = event.targetTouches ? event.targetTouches[0] : event
return {
x: e.clientX,
y: e.clientY
}
}
export default {
position
}