[英]How can i trigger two different tooltips at the same time using D3/javascript?
I have a d3/js interactive Geo map, where I created a tooltip on a mouseover event over a specific country.我有一个 d3/js 交互式 Geo map,我在其中创建了一个关于特定国家/地区上的鼠标悬停事件的工具提示。
The code that creates the tooltips is:创建工具提示的代码是:
// create a tooltip
var tooltip = d3.select("#tooltip")
.style("opacity", 0)
[..]
// create another tooltip
var tooltip2 = d3.select("#tooltip")
.style("opacity", 0)
.attr("class", "tooltip")
[..]
The code that triggers the tooltip is:触发工具提示的代码是:
.on("mouseover", mouseOver1 )
.on("mouseleave", mouseLeave )
where mouseOver1 is defined as:其中 mouseOver1 定义为:
d3.selectAll(".topo")
// [...]
tooltip
.style("opacity", 1)
.style("background-color", 'transparent')
.html( "<br/><img style='background:transparent; width=' 100 px'; height='"+(d.total)/10+"px' src='image.png'>")
// .style([..])
}
What i would like to do is to add a second function (mouseOver2) that will trigger a second tooltip, i want both tooltips to appear at the same time.我想做的是添加第二个 function (mouseOver2) 将触发第二个工具提示,我希望两个工具提示同时出现。
What i tried:我尝试了什么:
.on("mouseover.one", mouseOver1)
.on("mouseover.two", mouseOver2)
---> result; ---> 结果; the tooltip created with the second function (mouseOver2) still replaces the first one, or make the 1st one disappear when the 2nd one is called.
使用第二个 function (mouseOver2) 创建的工具提示仍然替换第一个,或者在调用第二个时使第一个消失。 (i created two different tooltips so they should be independent from each other)
(我创建了两个不同的工具提示,因此它们应该彼此独立)
In JavaScripy you can use addEventListener function to handle more function在 JavaScripy 中,您可以使用 addEventListener function 来处理更多 function
Doc: addEventListener()文档: addEventListener()
It's simple usage:用法很简单:
const el = document.getElementById('outside');
el.addEventListener("mouseenter", () =>{
functionFireToolTipOne();
functionFireToolTipTwo()
};
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.