为什么我的工具提示没有显示,如果我可以在源代码中看到它
Why my tooltip is not shown if I can see it in the source?
我写了一个显示图形的小网页,但现在我在显示工具提示时遇到了问题。它被正确地附加到DOM中,但我在页面上看不到它。
d3.selectAll("circle")
.on("mouseover", function(d){
d3.select(this)
.transition()
.attr("r", circle_size_hover)
.duration(transition_duration)
.style("opacity", 1);
d3.select(this)
.append("div")
.attr("class", "mytooltip")
.text(d.alarms)
.transition()
.style("opacity", 1);
console.log(d.alarms);
});
之后,我可以在DOM中看到我的div:
<g class="circles">
<circle cx="79.34074074074073" cy="113.50243902439024" r="7" style="opacity: 0.7;">
<div class="mytooltip">51.28205128205128</div>
</circle>
</g>
CSS:
.mytooltip {
position: absolute;
text-align: center;
width: 60px;
height: 28px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
JSFiddle:http://jsfiddle.net/L42LU/4/
您可以直接将html元素添加到正文中,并按照以下定位工具提示
d3.select("body").append("div").attr("class","tooltip")
.style("top",(d3.event.clientY - 10) + "px")
.style("left",(d3.event.clientX + 10) + "px")
.style("z-index", "10")
.style("visibility", "visible")
.text(d.alarms);
以上工具提示将显示在鼠标指针位置。在mouseout事件中,您可以通过更改可见性样式来隐藏此工具提示。
工具提示CSS:
div.tooltip {
position: absolute;
text-align: left;
padding: 8px;
font: 12px Verdana;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
在SVG中插入HTML元素(如<div>
)是无效的。您可以将工具提示作为foreignObject
元素插入SVG中。
相关文章:
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 我可以获得相对于被点击元素的确切点击位置吗
- 我可以更改剑道UI网格吗's的外键值
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 我可以在Javascript/jQuery中使用一个变量作为键吗
- 在Angular中,我可以从模板url中截取内容吗
- 我可以使此幻灯片图像自动播放吗?
- 我可以通过JQuery将CSS类交换为一个特殊的元素集吗
- JavaScript-为什么我可以在数组中设置键
- 我可以在Nodewebkit中保护javascript以外的资源吗
- 为什么我可以在Array属性对象中找到Javascript Array for Each方法
- Sails.js:我可以将一些服务/模型打包为npm并在Sails.jss应用程序中加载npm吗
- 我可以让我的Ajax调用引起一个“;进行中”;光标
- 变量dos'即使我可以返回更新后的值,也不会改变
- JavaScript/Ionic2-为什么我可以't检索localStorage值
- HTML4表单使用mattw@scriptarchive.comcgi脚本我可以嵌入贝宝按钮
- 我可以使用RubyonRails抓取URL的源代码吗?还是应该使用PHP
- 我可以使用Jquery获取元素的HTML源代码吗?
- 为什么我的工具提示没有显示,如果我可以在源代码中看到它