【发布时间】:2015-06-26 16:56:45
【问题描述】:
各位程序员好!
我正在 d3.js 中开发一个很酷的项目。目前我正在尝试制作工具提示,因为在 chrome 中它不会将标题属性显示为普通工具提示。
我在网上找到了2个解决方案:
-在单独的框中显示元素的跨度。我似乎没有让它在我的项目中工作。
-使用 d3 将 div 附加到 svg,以便在鼠标旁边出现一个浮动文本框。我设法完成了这项工作,但仅限于 chrome。如果我在 Firefox 中执行此操作,该框将出现在左下角。我什至尝试了 d3.mouse(this) 作为坐标,但它只是在意想不到的地方弹出。
在小提琴中,您可以看到两种“解决方案”。
http://jsfiddle.net/fbba7u8h/5/
ps。 firefox 似乎在“事件”方面遇到了麻烦。
//square是在html中定义的,红圈是在js d3代码中制作的 javascript:
d3.select("#square")
.on("mouseover", function(){return tooltip.style("visibility", "visible");})
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
var tooltip = d3.select("body")
.append("div")
.attr("class", "halloTip")
.text("this is a tooltip using d3 js, in chrome it hovers next to mouse, in firefox it pops up in the bottom left! I also tried d3.mouse(this)[0] and [1] at the onMouseMove");
//css样式:
.halloTip{
position:absolute;
z-index:10;
visibility:hidden;
text:qqq;
background-color:rgb(5, 225, 153);
stroke:black;
padding:11px;
}
.halloTip:hover{
visibility:hidden;
stroke-opacity:0.8;
}
【问题讨论】:
标签: javascript css firefox d3.js tooltip