Firefox event.clientX无法正常工作

ajs*_*han 0 javascript firefox javascript-events d3.js

我正在研究一个d3和js项目.

该函数的开头如下:

$(document).ready(function() { 
    d3.select("#aid").select(".abutton").on("mousemove",function() {
        afile.style("top", (event.clientY+10)+"px").style("left",(event.clientX+15)+"px");
        afile.html("<h3>Click text here</p><p>or here</p>");
    }); 
Run Code Online (Sandbox Code Playgroud)

我做了很多谷歌搜索!

本质上是在鼠标悬停时,它应该执行该功能.这适用于Chrome和IE,因为事件变量是全局的,因此它是客户端*属性.

据我所知,解决方案是传入一个eventObject.当我这样做时,我的代码看起来像:

$(document).ready(function() { 
    d3.select("#aid").select(".abutton").on("mousemove",function(event) {
        afile.style("top", (event.clientY+10)+"px").style("left",(event.clientX+15)+"px");
        afile.html("<h3>Click text here</p><p>or here</p>");
    });
Run Code Online (Sandbox Code Playgroud)

FF日志给了我:

[09:59:04.308] TypeError: event is undefined @ filepathofjavascriptfile
Run Code Online (Sandbox Code Playgroud)

同样,它在Chrome中断:未捕获的TypeError:无法读取未定义的filepathofjavascriptfile(匿名函数)help.js的属性'clientY':34 u

我究竟做错了什么?在此先感谢,如果您还有其他需要,请告诉我.

Poi*_*nty 6

尝试:

d3.select("#aid").select(".abutton").on("mousemove",function() {
    afile.style("top", (d3.event.clientY+10)+"px").style("left",(d3.event.clientX+15)+"px");
    afile.html("<h3>Click text here</p><p>or here</p>");
});
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,这就是d3如何暴露事件对象.