关于javascript:Firefox div> svg mouseover在div外部触发

Firefox div > svg mouseover fires OUTSIDE div

我有一个div,里面有两个svg元素,用鼠标悬停时会显示/隐藏这些元素。 将鼠标悬停事件注册到div

在Chrome和Safari上,它可以运行,在FF上,SVG位于不同的位置,并且我可以将鼠标悬停在div的" hitbox"上,非常大,例如div实际大小的3倍(通过Firebug进行检查, div也将宽度和高度设置为像素)。

鼠标悬停事件在比div占用的区域更大的区域触发怎么办?

Javascript:

1
2
3
4
$("#was_arrows").mouseover(function() {
        $('#was_arrows svg#normal').attr("class","hidden");
        $('#was_arrows svg#hover').attr("class","");
});`

HTML:

1
2
3
4
5
6
7
8
9
10
    <svg id="normal">
        <path d="M 5 0 l 0 30 l 15 -15 l -15 -15"/>
        <path d="M 25 0 l 0 30 l 15 -15 l -15 -15"/>
        <path d="M 45 0 l 0 30 l 15 -15 l -15 -15"/>
    </svg>
    <svg id="hover" class="hidden">
        <path d="M 5 0 l 0 30 l 15 -15 l -15 -15"/>
        <path d="M 25 0 l 0 30 l 15 -15 l -15 -15"/>
        <path d="M 45 0 l 0 30 l 15 -15 l -15 -15"/>
    </svg>

CSS:

1
2
3
4
5
6
7
8
#was_arrows {
    cursor: pointer;
    position:absolute;
    right: 40px;
    top: 23px;
    height: 30px;
    width: 53px;
}

链接:http://streuplan.feibra.at/streuplan/index.php?r = streuplan / go


您的元素没有width和height属性。 这意味着它们的尺寸为300 x 150像素(Chrome无法正确实现此功能,这就是您看到差异的原因)。 我不确定您要使用的内容是什么,但是以100%的宽度和高度开始将不合理。