22

通常,该<clipPath>元素会隐藏剪辑路径之外的所有内容。为了达到相反的效果——即从图像中“剪掉”一些东西——我想在 clipPath 和clip-rule="evenodd"属性中使用两条路径。基本上,我想“异或”剪辑路径。

但它不起作用。它显示区域“ORed”:

<clipPath clip-rule="evenodd" id="imageclippath" clipPathUnits = "objectBoundingBox">
        <rect clip-rule="evenodd" x="0.3" y="0.3" height="0.6" width="6" />
        <rect clip-rule="evenodd" x="0" y="0" height="0.5" width="0.5" />
    </clipPath>     

 <rect clip-path="url(#imageclippath)" x="0" y="0" height="500" width="500" fill="red"/>

编辑:

我的问题是 AFAIK<mask>在 iOS WebKit 中不起作用。

4

1 回答 1

34

用面具做你想做的事情要容易得多,请看这个例子。这是掩码定义:

<mask id="maskedtext">
  <circle cx="50%" cy="50%" r="50" fill="white"/>
  <text x="50%" y="55%" text-anchor="middle" font-size="48">ABC</text>
</mask>

蒙版内的白色区域将被保留,其他所有区域都将被剪掉。

这是另一个使用 clipPath 的示例,它有点棘手,因为您需要使用路径元素来应用剪辑规则。那里使用剪辑规则的剪辑路径如下所示:

<clipPath id="clipPath1">
  <path id="p1" d="M10 10l100 0 0 100 -100 0ZM50 50l40 0 0 40 -40 0Z" clip-rule="evenodd"/>
</clipPath>
于 2011-01-27T15:31:51.397 回答