简体   繁体   English

工具提示未相对于 cursor 定位

[英]Tooltip not positioning relative to cursor

I have 2 pages that use Tooltip.我有 2 个页面使用工具提示。 One does what I expect (the tooltip moves relative to the cursor) but the other doesn't.一个做我所期望的(工具提示相对于光标移动),但另一个没有。 The d3.event.pageY and d3.event.pageX both are what I expect in the console.log but the tooltips in the html do not move (as if d3.event.pageY is zero). d3.event.pageY 和 d3.event.pageX 都是我在 console.log 中所期望的,但 html 中的工具提示不会移动(好像 d3.event.pageY 为零)。

Any idea what can be the cause?知道可能是什么原因吗?

   .on ("mouseover" , function ( d ) { 
     if (d.properties.rate == null) { d.properties.rate = 0} else {console.log ("d3.event.pageY - tooltipTop ", d3.event.pageY - tooltipTop)};
        div.transition () 
        .duration ( 200 ) 
        .style ( "opacity" , 1 ); 
        div.html ("<p>" + d.properties.PHU_NAME_E + "</p><p>" + formatInteger(d.properties.rate) + " cases per million</p>") 
        .style ( "left" , ( d3.event.pageX - tooltipLeft) + "px" ) 
        .style ( "top" , ( d3.event.pageY - tooltipTop ) + "px" ); 
        }) // end of mouseover
    .on ( "mouseout" , function ( d ) { 
        div.transition () 
        .duration ( 500 ) 
        .style ( "opacity" , 0 ); 
        }); // end of mouseout;

Complete Code: https://jsfiddle.net/PatriciaW/q6da7zj9/2/完整代码: https://jsfiddle.net/PatriciaW/q6da7zj9/2/

Not a problem any more: I have done something that has fixed this (using both d3.mouse(this) and d3.event.pageX).不再是问题了:我已经解决了这个问题(使用 d3.mouse(this) 和 d3.event.pageX)。 I have no idea what it was.我不知道那是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM