如何传递在d3.js中调用javascript事件的同一对象
how to pass same object on which javascript event is called in d3.js
我正在使用d3.js,并使用它创建了svg,我在上面绘制了地图和圆。有许多圆圈,每个圆圈都有唯一的id,但属于同一类。现在,当我将鼠标悬停在它们上面时,我想通过调用oneevent函数来进行一些转换。
以下是HTML页面的结构
table
tbody
tr
td
svg
rect (boundary of canvass)
g
g
path
circle id(xyz)
g
path
circle(pqr)
我希望当我悬停在任何一个圆圈上时,只有那个圆圈应该显示do过渡。
这是我的代码,它不起作用。
var radius=(weekData[q].bob[p].reach)/15;
d3.select("body").select("svg").select("#outerG").append("g").append("circle")
.attr("cx",coords[0])
.attr("cy",coords[1])
.attr("r",radius)
.attr("class","circle")
.attr("id","xyz")
.style('fill', 'tan')
.attr("onmouseover","myHoverFunction(this)")
.attr("onmouseout","myHoverOutFunction(this)");
function myHoverFunction(obj)
{
d3.select("this.obj").transition()
.duration(1000)
.attr("r",40)
.attr("stroke","red")
.attr("stroke-width",4);
}
请告诉我怎样才能解决这个问题。
您的代码应该是这样的。
d3.select("body").select("svg").select("#outerG").append("g").append("circle")
.attr("cx",coords[0])
.attr("cy",coords[1])
.attr("r",radius)
.attr("class","circle")
.attr("id","xyz")
.style('fill', 'tan')
.on("mouseover", myHoverFunction);
function myHoverFunction() {
d3.select(this).transition()
.duration(1000)
.attr("r",40)
.attr("stroke","red")
.attr("stroke-width",4);
}
我无法轻松测试它,但您可以尝试:
d3.select("#outerG")
.append("g").append("circle")
.attr( {
cx: coords[0],
cy: coords[1],
r: radius,
class: 'circle',
id: 'xyz'
} )
.style('fill', 'tan')
.on("mouseover", myHoverFunction)
.on("mouseout", myHoverOutFunction)
function myHoverFunction() {
d3.select(this).transition()
⋮
相关文章:
- 如何从jQuery的事件对象中检索属性
- 如何在JavaScript中基于事件对象获取文件名
- 如何避免在这种情况下修改事件对象
- 如何在事件处理程序中获取 javascript 事件对象
- 如果在设置侦听器之前触发了 DOMContentLoaded 事件,如何检索“事件”对象
- addEvent 给出空事件对象
- 修改鼠标事件对象的“目标”以进行事件委派
- 如何将参数传递给backbone.js中事件对象中绑定的函数
- 从ng重复奇数内部的ng点击访问事件对象
- 如何从 React 中的事件对象访问自定义属性
- 如何将事件对象传递给对象中的函数
- 正在发送事件对象
- 是否可以获得“”的事件对象;当前“;或“;最后一个“;事件,而不将其作为处理程序中的参数接收
- 如何将事件对象字符串化
- 通过angular传递关于事件预防的信息;s事件对象
- Javascript事件对象:其中是选择器
- Meteor.js:如何检索事件对象的父元素的数据属性
- JavaScript 如何重新识别事件对象变量
- 事件对象在此代码中的工作原理
- 是为响应 DOM 事件而创建的多个事件对象