2015-11-03 123 views

回答

1

您目前在您的代码中没有任何event listeners。您需要将事件侦听器添加到要让鼠标悬停事件显示的对象。例如:

d3.select('svg.chord').on('mouseenter', function() { *show image here* }) 

D3还有一个方便的功能,让网页上的鼠标的当前位置: https://github.com/mbostock/d3/wiki/Selections#d3_event

d3.event.pageYd3.event.pageX

所以,你需要改变图像的风格属性匹配鼠标位置。这样的事情:

d3.select('svg.chord').on('mouseenter', function() { 
    d3.select(this).append('img').attr({src:'/my/url'}) 
    .style({ 
    position:absolute, 
    top: d3.event.pageY, 
    left: d3.event.pageX}) 
}).on('mouseexit', function() { 
    d3.select('img').remove(); 
}) 

希望这会有所帮助!