将过滤器添加到svg中的裁剪元素(组合clipPath和filter元素)

编程入门 行业动态 更新时间:2024-10-28 18:31:36
本文介绍了将过滤器添加到svg中的裁剪元素(组合clipPath和filter元素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否可以将svg过滤器应用于剪切的html内容.我发现的所有演示都有单独的剪辑和过滤.

I wonder if it's possible to apply svg filter to clipped html content. All demos I found have clipping and filtering separate.

这里是一个示例: jsfiddle/B7593/1/.我希望黄色圆圈能遮住阴影.

Here's an example: jsfiddle/B7593/1/. I want the yellow circle to drop a shadow.

尝试将 filter = url('#dropshadow')/ style ='filter:url(#dropshadow)'添加到 circle / clipPath / div 元素,但这些都不起作用.

Tried adding filter=url('#dropshadow') / style='filter:url(#dropshadow)' to circle / clipPath / div elements, but none of these worked.

推荐答案

我认为您无法以接近它的方式进行操作-即使您可以将阴影作为片段的一部分,也不会由于没有保留任何颜色,因此在应用剪辑时看不到它,仅使用像素的不透明度来确定显示的内容.至少在Firefox中有效的方法是,将片段和过滤器同时应用于SVG中的内容,如下所示:

I don't think you can do it the way you're approaching it - even if you could make the shadow a part of the clip, you wouldn't see it when you applied the clip because none of the colour is retained, just the opacity of the pixels is used to determine what shows through. What will work (in Firefox at least), is to apply both the clip and the filter to content within the SVG like this:

<g filter="url(#dropshadow)"> <foreignObject width="300" height="300" clip-path="url(#c1)"> <body> <div id="target"></div> </body> </foreignObject> </g>

这里是一个完整的示例.

更多推荐

将过滤器添加到svg中的裁剪元素(组合clipPath和filter元素)

本文发布于:2023-11-09 17:25:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   组合   过滤器   filter   svg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!