【问题标题】:How can i set default color on element after mouse out D3鼠标移出D3后如何在元素上设置默认颜色
【发布时间】:2017-06-19 05:10:49
【问题描述】:

我有一个强制有向图,我喜欢突出它的父母并使它们比其他的大一点我可以使它们成为新的颜色并使它们变得更大,但我无法将它们恢复为默认大小和颜色。 每当我将鼠标移到元素上时,它都会将它们全部变为绿色,但是当我移出鼠标时,只有中心元素会改变颜色,但它不会返回到它自己的颜色,它会返回到我将鼠标放在上面的颜色。

function highlightParents(d) {
    var colour = d3.event.type === 'mouseover' ? 'green' : color(d.group);
    d3.select('#id-' + parseInt(d.id)).style('fill', colour);
    var bid = "";
    for (var i = 0; i < link._groups[0].length; i++) {

        if (link._groups[0][i].attributes[0].value.replace("t-", "") == d.id) //target
        {

            bid += link._groups[0][i].attributes[1].value.replace("s-", ""); //source
            d.id = link._groups[0][i].attributes[1].value.replace("s-", "");  //source


            var colour = d3.event.type === 'mouseover' ? 'green' : color(d.group);
            d3.select('#id-' + parseInt(d.id)).style('fill', colour);
            var setr = d3.event.type === 'mouseover' ? '7' : 5;
            d3.select('#id-' + parseInt(d.id)).style('r', setr);                         
            i = 0;
            if (link._groups[0][i].attributes[1].value == "304410") {
                break;
                d3.selectAll('#id-' + parseInt(d.id)).style('fill', (d.group));

            }
        }
    }
}

【问题讨论】:

    标签: javascript css d3.js


    【解决方案1】:

    你能用'mouseout'事件吗?

    例如:

    function highlightParents(d) {
      var colour = color(d.group);
      if (d3.event.type === 'mouseover') colour = 'green';
      if (d3.event.type === 'mouseout') colour = 'red';
      ...
    

    【讨论】:

    • var color = d3.event.type === 'mouseover' ? “绿色”:颜色(d.group);我认为这已经询问是否结束或结束,但感谢您的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2014-04-05
    • 2016-05-24
    • 2014-06-10
    • 2019-02-08
    相关资源
    最近更新 更多