<defs> <maskid="mask3"x="0"y="0"width="100"height="100" > <rectx="0"y="0"width="100"height="50"style="stroke:none; fill: #ffffff"/> <rectx="0"y="50"width="100"height="50"style="stroke:none; fill: #666666"/> </mask></defs><textx="10"y="55"style="stroke: none; fill: #000000;"> This text is under the rectangle</text><rectx="1"y="1"width="100"height="100"style="stroke: none; fill: #0000ff; mask: url(#mask3)"/>
这个例子的矩形下方有一个文本,其仅可通过矩形遮罩是半透明的部分可见。
最终图片如下:
<text x="10" y="55" style="stroke: none; fill: #000000;">This text is under the rectangle</text>
<rect x="1" y="1" width="100" height="100" style="stroke: none; fill: #0000ff; mask: url(#mask3)"></rect>
<defs> <linearGradientid="gradient1"x1="0%"y1="0%"x2="100%"y2="0%"spreadMethod="pad"> <stopoffset="0%"stop-color="#ffffff"stop-opacity="1"/> <stopoffset="100%"stop-color="#000000"stop-opacity="1"/> </linearGradient> <maskid="mask4"x="0"y="0"width="200"height="100" > <rectx="0"y="0"width="200"height="100"style="stroke:none; fill: url(#gradient1)"/> </mask></defs><textx="10"y="55"style="stroke: none; fill: #000000;"> This text is under the rectangle</text><rectx="1"y="1"width="200"height="100"style="stroke: none; fill: #0000ff; mask: url(#mask4)"/>
最终图片如下:
<mask id="mask4" x="0" y="0" width="200" height="100">
<rect x="0" y="0" width="200" height="100" style="stroke:none; fill: url(#gradient1)"></rect>
</mask>
</defs>
<text x="10" y="55" style="stroke: none; fill: #000000;">This text is under the rectangle</text>
<rect x="1" y="1" width="200" height="100" style="stroke: none; fill: #0000ff; mask: url(#mask4)"></rect>
渐变遮罩可以与其它效果(如填充图案)组合。下面例子中的可见矩形同时使用了填充图案和渐变遮罩:
<defs> <linearGradientid="gradient2"x1="0%"y1="0%"x2="100%"y2="0%"spreadMethod="pad"> <stopoffset="0%"stop-color="#ffffff"stop-opacity="1"/> <stopoffset="100%"stop-color="#000000"stop-opacity="1"/> </linearGradient> <patternid="pattern2"x="10"y="10"width="20"height="20"patternUnits="userSpaceOnUse" > <circlecx="10"cy="10"r="10"style="stroke: none; fill: #0000ff; " /> </pattern> <maskid="mask6"x="0"y="0"width="200"height="100" > <rectx="0"y="0"width="200"height="100"style="stroke:none; fill: url(#gradient2)"/> </mask></defs><textx="10"y="55"style="stroke: none; fill: #000000;"> This text is under the rectangle</text><rectx="1"y="1"width="200"height="100"style="stroke: none; fill: url(#pattern2); mask: url(#mask6)"/>