在update()转换期间绑定事件 [英] Binding an event during an update() transition

查看:106
本文介绍了在update()转换期间绑定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在转换期间将事件绑定到选择?

Is it possible to bind an event to a selection during a transition?

例如,假设这是您的更新:

For example, let's say this is your update:

        g3.selectAll(".circles")
          .data(dataFiltered, function(d){ return d['token']})
          .transition().delay(circleDelay).duration(1200)
              .attr('r', pointRadius + "px")
              .attr('stroke', '#fff')
              .attr('stroke-width', 1.5)
              .attr("fill",function(d,i){ return (typeof(d[3]) === 'string') ? colorize(d[3]) : null })
              .style('cursor',"pointer")
              .attr('class',"circles");

它会引发一个错误链接 .on('mouseover',function mouseoverlogic (){});

It throws an error to chain .on('mouseover',function mouseoverlogic(){});

c $ c> pattern,可以在 exit()

推荐答案

由于转换是一种特殊类型的选择,因此不能使用转换中所有可用的选项。而应使用 transition.each()将处理程序绑定到转换。

Since transitions are a special kind of selections you cannot use all methods available to a selection on a transition. Instead, use transition.each() to bind your handler to the elements in the transition.

.transition()
    .each(function () {
        d3.select(this).on('mouseover', function mouseoverlogic() {});
    });

这篇关于在update()转换期间绑定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆