0%

Js 拦截鼠标事件

https://stackoverflow.com/questions/20014390/intercept-all-mouse-events

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var eventCount = 0;
var eventProperty = [];

var TrackMouse = function (mouseEvent) {
eventProperty[eventCount++] = {
id: mouseEvent.toElement.id,
type: 'mouse',
ts: Date.now(),
x: mouseEvent.x,
y: mouseEvent.y,
};

console.log(
'Element id: ' +
eventProperty[eventCount - 1].id +
', X: ' +
mouseEvent.x +
', Y: ' +
mouseEvent.y +
'\n'
);
};

document.addEventListener('click', TrackMouse);