简体   繁体   English

外部对象显示:Firefox和Chrome中没有

[英]foreignObject display:none in Firefox and Chrome

I have a JavaScript app that works with svg components. 我有一个可与SVG组件配合使用的JavaScript应用。 I have svg groups as: 我有svg组:

<svg id="canvas" width="100%" height="100%" viewBox="0 0 1500 500">
    <g class="node-element" x="0" y="0" height="20" width="300" id="node-c87">
        <text class="node-element-text" x="12" y="15">person:object</text>    
        <image x="0" y="4" width="11" height="11" xlink:href="assets/images/object-icon.png"></image>
    </g>
    <g class="nested-group">
        <g class="node-element" x="50" y="100" height="20" width="300" id="node-c87">
            <text class="node-element-text" x="12" y="15">person:object</text>    
            <image x="0" y="4" width="11" height="11" xlink:href="assets/images/object-icon.png"></image>
        </g>
    </g>
</svg>

And I have defined CSS as follows(CSS on svg groups acts on all child elements of <g> . 而且我对CSS的定义如下(svg组上的CSS作用于<g>所有子元素。

.node-element {
    display: inline;
}
.node-element :active {
    opacity: 0.5;
}
.node-element:hover {
    opacity: 0.5;
}

The problem is that it does not work properly in Firefox, whereas it works fine in Chrome. 问题在于它在Firefox中无法正常运行,而在Chrome中则可以正常运行。 Why and how to fix it? 为什么以及如何解决?

The node elements are in a tree-like structure where x values differ based on rank. 节点元素采用树状结构,其中x值基于等级而不同。 In Firefox, the hover does not properly work on the first couple of node-elements. 在Firefox中,悬停无法在前几个节点元素上正常工作。 But works fine on the rest of the node-elements, regardless of the x values . 但是, 无论x值如何,在其余节点元素上都可以正常工作

UPDATE: The problem was actually caused by a foreignObject component, which I have set the elements to display:none . 更新:问题实际上是由foreignObject组件引起的,该组件已将元素设置为display:none The hover was actually working on the hidden component than the desired element. 悬停实际上在隐藏的组件上工作,而不是所需的元素。 It was solved by setting the display:none to the foreignObject. 通过将display:none设置为foreignObject可以解决此问题。

But I would like to know why this was acting differently in the two browsers, Chrome and Firefox? 但是我想知道为什么这两种浏览器(Chrome和Firefox)的行为不同?

You probably need to have all look at css pointer-events , documented here . 您可能需要全部关注css pointer-events在此处记录 pointer-events With that you can specify what »region« of your graphic is used for hovers. 这样,您可以指定图形的哪个“区域”用于悬停。 This can be the AABB (axis aligned Bounding box, nothing or the shape of the graphic). 可以是AABB(轴对齐的边界框,什么也不是图形的形状)。

The problem was actually caused by a foreignObject component, which I have set the elements to display:none . 该问题实际上是由foreignObject组件引起的,该组件已将元素设置为display:none The hover was actually working on the hidden component than the desired element. 悬停实际上在隐藏的组件上工作,而不是所需的元素。 It was solved by setting the display:none to the foreignObject. 通过将display:none设置为foreignObject可以解决此问题。

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

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