使用 SVG 勾勒出一组感人的形状
对于我想要的某种风格,我想在 SVG 中勾勒出一组形状。应用于组时,lines
属性似乎单独勾画出每个形状的轮廓,有效地位于附近其他形状的顶部。为了更清楚地解释我的情况:我有一组触摸矩形,每个矩形都是 8x8 像素。然而,它们并没有形成更大的矩形。
为了简单起见,我们假设它们形成一个十字。所以我有 5 个矩形——1 个在中心,另外一个在该矩形的每一侧。我想把它们全部勾勒出来,就好像它们是一个形状一样。鉴于这种“十字”形状发生变化,我宁愿不使用路径,因为这需要更多的编码。有没有什么方法可以让效果过滤器将这组识别为单个形状?
如果没有,是否至少可以制作该组的黑色副本,其宽度和高度恰好大 2px,我可以将其放置在该组后面以创建纯黑色轮廓?如果是这样,是否可以不重复该组?
感谢您的帮助。
For a certain style I'm going for, I want to outline a group of shapes in SVG. Applied to a group, the stroke
property appears to outline each shape individually--effectively going on top of other shapes nearby. To explain my situation more clearly: I have a group of touching rectangles that are 8x8 pixels each. They do not form a larger rectangle, however.
For simplicity's sake, let's say they form a cross. So I have 5 rectangles--1 in the center and one more on each side of that one. I want to outline them all as if they were 1 shape. Given that this "cross" shape changes, I would prefer not to use paths since that would require a lot more coding. Isn't there any way that I could get the effects filter to recognize this group as a single shape?
If not, is it at least possible to make a black copy of this group that's exactly 2px larger in width and height that I can position behind the group to create a solid black outline? And if so, is it possible without duplicating the group?
Thank you for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
例如,您可以使用像这样的 svg 过滤器:
使用像这样的过滤器:
另一种可能有效的替代方案,具体取决于您的内容的外观,如下所示:
You could use an svg filter like this one for example:
Use the filter like this:
Another alternative that might work, depending on how your content looks is something like this:
像这样:
http://jsfiddle.net/longsonr/LrDHT/1/ 单击矩形,它变得黑色并且更大。
您可以使用 feMerge 扩展过滤器以将原始形状放在顶部
Like this:
http://jsfiddle.net/longsonr/LrDHT/1/ click on the rectangle and it becomes black and bigger.
You could extend the filter to put the original shape on top using feMerge
这是没有 SVG 过滤器的答案:
这样做的好处是,在 HTML 中,您可以使矩形透明,并仅使用以下方式显示轮廓:(
不幸的是,对于 SVG 情况,这对我不起作用)
http://jsfiddle.net/EoghanM/9ua5fyjx
Here's an answer without SVG filters:
The nice thing about this is that in HTML you can have the rectangles transparent, and just show the outline using:
(Unfortunately that bit wouldn't work for me for the SVG case)
http://jsfiddle.net/EoghanM/9ua5fyjx