SVG 图像不透明度渐变

SVG Image opacity gradient

我在 .svg 文件中使用这段代码在元素上应用不透明度淡出渐变。以下代码运行良好,但从左到右淡化,而不是从上到下垂直淡化。

我需要更改什么代码才能实现此目的?感谢您的帮助!

SVG 文件:

<?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
      "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg xmlns="http://www.w3.org/2000/svg"
         version="1.1"
         baseProfile="full">
         <mask id="m1" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
            <linearGradient id="g" gradientUnits="objectBoundingBox" x2="1">
              <stop stop-color="white" offset="0"/>
              <stop stop-color="white" stop-opacity="0" offset="1"/>
            </linearGradient>
            <rect x="0" y="0" width="1" height="1" fill="url(#g)"/>
          </mask>
    </svg>

CSS:

mask: url(/mypath/mask.svg#m1);

您可以使用 x1y1x2y2 属性设置渐变的方向。

对于从顶部开始向下的垂直渐变,您需要从 (0,0) 到 (0,1)。

<linearGradient id="g" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="0" y2="1">
    <stop stop-color="white" offset="0"/>
    <stop stop-color="white" stop-opacity="0" offset="1"/>
</linearGradient>