javascript - 有没有 'only run when the mouse is over but stop when its not over'的javascript命令

标签 javascript d3.js

我知道 onmouseover 但我在页面上有一个圆圈,当鼠标悬停在它上面时该圆圈会亮起。但当鼠标离开它时,它会保持亮起状态,直到它再次悬停,然后再次关闭。真的很烦人。有没有一个指令只在悬停时触发?这是代码,但大部分不相关

var node = svg.selectAll(".node")
      .data(graph.nodes)
      .enter().append("circle")
      .attr("class", "node")
      .attr("r", function(d) { return d.group * 3; })
      .style("fill", function(d) { return color(d.group); })
      .call(force.drag)
      .on('mouseover', connectedNodes)
      .on("click",  function(d) { getprofile(d); });

最佳答案

您需要定义鼠标移出事件。 所以你的代码将是这样的:

    var node = svg.selectAll(".node")
          .data(graph.nodes)
          .enter().append("circle")
          .attr("class", "node")
          .attr("r", function(d) { return d.group * 3; })
          .style("fill", function(d) { return color(d.group); })
          .call(force.drag)
          .on('mouseover', connectedNodes)
          .on('mouseout', doSomethingCallback)
          .on("click",  function(d) { getprofile(d); });

function doSomethingCallback(){
  fill your circle with the original color
}

关于javascript - 有没有 'only run when the mouse is over but stop when its not over'的javascript命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30874963/

相关文章:

javascript - 无法设置 null 错误的innerHTML。虽然 html ID 存在

javascript - D3.js 版本 4 : How to properly set the x-axis-intervals for a histogram

javascript - d3v4 "columns"的替代方案(我必须使用 d3v3)

javascript - 根组件在路由器导出中呈现自己

javascript - jQuery 按钮一次验证表单的一部分

javascript - shouldComponentUpdate 的更好替代方案

javascript - 浏览器中的 Bash 控制台

javascript - 如何进行线性插值?

javascript - 如何对我的 json 数据文件使用量化功能

javascript - d3.svg.diagonal() 在哪里?