繁体   English   中英

d3事件绑定时如何访问原始事件对象

[英]How to access original event object when d3 event binding

在d3中,我将节点上的mousedown事件绑定到我想要执行的函数:

let node = gA.svg.selectAll('.node').data(gA.force.nodes(), gA.node_id)
let node_group = node.enter().append('g')
    .classed('node', true)
    .call(gA.drag)

node_group.append('circle')
    .classed('node-circle', true)
    // we may consider adding the position too. it will get updated on the 
    // next tick anyway, so we will only add it here if things look glitchy
    .attr('r', gA.node_radius) 
    .on(gA.circle_events)
    .on('mousedown', mousedown)
    .on('mouseup', mouseup)

这里只有最后一行真正相关。 那和我正在使用d3的事实。

但是现在当我定义我的鼠标功能时......

function mouseup(datum, something1, something2) {
    alert("But where is the Event object?  :(  :'(  ")
}

datum是绑定到svg“circle”的基准。 something1似乎是鼠标相对于元素的x位置(我的最佳猜测)。 而且某些东西似乎是y位置。

但是如何访问活动? 我需要访问Event.clientX。

这有很好的记录

d3.event

存储当前事件(如果有)。 在使用on运算符的事件侦听器回调期间注册此全局。 在finally块中通知侦听器后,将重置当前事件。 这允许侦听器函数具有与其他运算符函数相同的形式,传递当前数据d和索引i。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM