【问题标题】:SVG pattern inconsistency between chrome and firefoxchrome 和 firefox 之间的 SVG 模式不一致
【发布时间】:2012-02-14 07:53:56
【问题描述】:

我有一个渐变覆盖指定为图案的纯色(红色):

<svg width="480" height="480">
    <defs>

        <pattern width="1" height="1" x="0" y="0" id="pattern">
            <rect width="240" height="240" x="0" y="0" fill="rgba(255,0,0,1)"/>
            <rect width="240" height="240" x="0" y="0" fill="url(#gradient)"/>
        </pattern>

        <linearGradient id="gradient" x1="0" y1="1" x2="0" y2="0">
            <stop offset="0%" stop-color="rgb(0,0,0)" stop-opacity="1"/>
            <stop offset="100%" stop-color="rgb(0,0,0)" stop-opacity="0"/>
        </linearGradient>

    </defs>
    <path
      transform="matrix(1,0,0,1,200,200)"
      d="M0 0M 120 0 A 120 120 0 0 0 -120 0 A 120 120 0 0 0 120 0"
      fill="url(#pattern)"
    />
</svg>

左:火狐。右:铬

右边的(Chrome)是正确的。

有谁知道如何在 Firefox 中进行这项工作?

现场观看:http://jsbin.com/eyenoh/edit#html,live

【问题讨论】:

    标签: firefox google-chrome svg


    【解决方案1】:

    我能够通过使用对象边界框作为模式内容的坐标系来使其工作。

    <pattern width="1" height="1" x="0" y="0" id="pattern" patternContentUnits="objectBoundingBox">
        <rect width="1" height="1" x="0" y="0" fill="rgba(255,0,0,1)"/>
        <rect width="1" height="1" x="0" y="0" fill="url(#gradient)"/>
    </pattern>
    

    在这里查看: http://jsbin.com/efesev/edit#html,live

    我会尝试进一步调查。看起来是一个不错的错误报告候选者。

    【讨论】:

    • 等等,它变得更好了 - jsbin.com/eyenoh/2/edit#html,live 绝对是一个错误!
    • &lt;circle&gt;(工作不一致)和&lt;path&gt;(如果没有patternContentUnits="objectBoundingBox",永远不会工作)的行为似乎略有不同
    猜你喜欢
    • 1970-01-01
    • 2021-11-20
    • 2013-11-14
    • 2017-06-29
    • 2016-04-19
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多