Skip to content

JS 拦截鼠标事件

Published: at 05:04 PMSuggest Changes

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

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);

Previous Post
Vue.js 实用技巧:使用 .sync 修饰符实现父子组件数据同步
Next Post
JavaScript 背景动画插件 particles.js