d3.event
The current event, if any. This is set during the invocation of an event listener, and is reset after the listener terminates. Use this to access standard event fields such as event.timeStamp and methods such as event.preventDefault. While you can use the native event.pageX and event.pageY, it is often more convenient to transform the event position to the local coordinate system of the container that received the event using d3.mouse, d3.touch or d3.touches.
If you use Babel, Webpack, or another ES6-to-ES5 bundler, be aware that the value of d3.event changes during an event! An import of d3.event must be a live binding, so you may need to configure the bundler to import from D3’s ES6 modules rather than from the generated UMD bundle; not all bundlers observe jsnext:main. Also beware of conflicts with the window.event global.
event通过事件绑定获得,你可以通过 d3.event获得event.pageX 的使用,当你使用event.pageX或者event.pageY 的时候,可以考虑更方便的d3.mouse
如果你使用babel,webpack等转换es6->es5 的时候,小心d3.event改变了,你必须通过import引入d3,而不是通过umd方式,另外需要区分和window.event
的区别