admin管理员组文章数量:1333442
I have some tootips in my page. There is one tooltip(div) contains a input box and a button. I want to click outside the tooltip and then hide the tooltip. I tried this:
d3.select("body")
.on("click",function(){
d3.select("#tooltip")
.classed("hidden",true);
});
This works, but when I click the input box want to input some value, the tooltip still hide. How can I hide the tooltip only when I click outside the tooltip?
I also tried:
d3.select("body").filter().on("click",function(){})
But I don't how it works, I cannot select all elements except the tooltip(div).
I have some tootips in my page. There is one tooltip(div) contains a input box and a button. I want to click outside the tooltip and then hide the tooltip. I tried this:
d3.select("body")
.on("click",function(){
d3.select("#tooltip")
.classed("hidden",true);
});
This works, but when I click the input box want to input some value, the tooltip still hide. How can I hide the tooltip only when I click outside the tooltip?
I also tried:
d3.select("body").filter().on("click",function(){})
But I don't how it works, I cannot select all elements except the tooltip(div).
Share Improve this question asked Apr 6, 2016 at 4:37 YaweiYawei 931 silver badge8 bronze badges1 Answer
Reset to default 6Here is a solution:
var tooltip = d3.select("#tooltip");
var tooltipWithContent = d3.selectAll("#tooltip, #tooltip *");
function equalToEventTarget() {
return this == d3.event.target;
}
d3.select("body").on("click",function(){
var outside = tooltipWithContent.filter(equalToEventTarget).empty();
if (outside) {
tooltip.classed("hidden", true);
}
});
JSFiddle: https://jsfiddle/LukaszWiktor/53yok58w/
本文标签: javascriptd3js when click outside the elementshide the elementStack Overflow
版权声明:本文标题:javascript - d3.js when click outside the elements, hide the element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354550a2459154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论