d3js删除元素的过渡

法赞

我有一个SVG图像(alpha),我想在鼠标悬停时显示一些控制选项组,并在鼠标悬停时隐藏它们。

假设我在中有图像alpha x=100, y=100我的svg中有一个预定义的工具提示分类组,其样式为'visibility':'hidden'。我改变风格可见,我将其x,y坐标alpha.attr('x')-20alpha.attr('y')-20这样它就出现在图像的左上角。但是,当我从图像中将鼠标移出时,小组将自己隐藏起来,为解决该问题,我延迟了该setTimeOut()功能。但是,当我将鼠标悬停在对照组上时,由于延迟,它将样式更改为隐藏。

我尝试使用,d3.transition但将鼠标悬停在对照组后就无法弄清楚如何将其删除。

我不知道如何克服这个问题并达到我的要求。谁能帮我?

d3.select('#svg')
    .append('g')
    .attr('id', 'playground')
    .append('image')
    .attr('class', 'tooltip')
    .attr('width', 20)
    .attr('height', 20)
    .attr('x', 0)
    .attr('y', 0)
    .attr('xlink:href', base_url + '/assets/svg/api_lbs_color.svg')
    .style('visibility', 'hidden')
    .on('mouseover', function () {
        d3.select(this).style('visibility','visible');
    })
    .on('mouseout', function () {
        d3.select(this).style('visibility','hidden');

    });

playGround
            .append('image')
            .attr('width', 32)
            .attr('height', 32)
            .attr('x', d3.mouse(this)[0])
            .attr('y', d3.mouse(this)[1])
            .attr('xlink:href', curr.attr('xlink:href'))
            .on("mouseover", function(d) {  // the mouseover event
                console.log('mouse over playgrround operator');

                var curr = d3.select(this);

                d3.select('.tooltip')
                    .attr('x', curr.attr('x') - 20)
                    .attr('y', curr.attr('y') - 20)
                    .style('visibility', 'visible')
                ;


            })
            .on('mouseout', function () {

                setTimeout(function () {
                    d3.select('.tooltip')
                        .style('visibility', 'hidden')

                }, 1000);


            })
        ;
阿比斯堡

我不太了解您想要的功能,但我认为过去也遇到过类似的问题。您应该使用mouseentermouseexit事件而不是mouseovermouseout,这将使工具提示在光标位于image元素内时仍然可见。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章