我想使用 mix-blend-mode 属性使某些特定的 SVG 路径在笔划上采用背景图像,以便路径看起来好像是擦除路径。以下代码是我所达到的。但是,如您所见,mix-blend 属性会影响其他路径,这些路径需要在笔划上没有任何背景图像的情况下出现。因此,我要求一种方法将 mix-blend-mode 属性仅应用于单独的元素组,并使其他元素不受影响。
g.erasing image{
mix-blend-mode: lighten;
}
<html>
<body>
<svg height="400" width="450">
<!-- this is the background image -->
<image id="background" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg" width="400" height="450"></image>
<g class="drawing">
<!-- these are the drawing paths -->
<path d="M 100 350 l 150 -300" stroke="red" stroke-width="8" fill="none" />
<path d="M 250 50 l 150 300" stroke="red" stroke-width="8" fill="none" />
<path d="M 175 200 l 150 0" stroke="green" stroke-width="8" fill="none" />
<path d="M 100 350 q 150 -300 300 0" stroke="blue" stroke-width="8" fill="none" />
</g>
<g class="erasing">
<!-- these are the erasing paths -->
<path d="M 0 0 L 400 450" stroke="black" stroke-width="20" />
<path d="M 0 0 L 200 300" stroke="black" stroke-width="20" />
<image xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg" width="400" height="450"></image>
</g>
</svg>
</body>
</html>
以下是我所寻求的。
注意:我可以使用屏蔽来做到这一点,但在某些浏览器中它非常慢。