简体   繁体   English

有没有办法让 svg 不是矩形?

[英]Is there any way to render svg not rectangular?

Please see this image for clarity [1]: https://i.stack.imgur.com/fgA6g.png为了清楚起见,请查看此图像 [1]: https://i.stack.imgur.com/fgA6g.png

I use svgs for painting in a web page.我在 web 页面中使用 svgs 进行绘画。 The problem is they are rendering as rectangle and making an unwanted common area witch makes the coloring difficult.问题是它们渲染为矩形,并且使不需要的公共区域女巫使着色变得困难。 I want them without the empty space around them.我希望他们没有周围的空白空间。 For example in the example above the whole blue section is clickable witch makes part of the other svg unreachable.例如在上面的例子中,整个蓝色部分是可点击的,这使得其他 svg 的一部分无法访问。

import SVG from 'react-inlinesvg';

<div
              key={object.id}
              className="click-object"
              style={{
                position: 'absolute',
                left: `${object.x}%`,
                top: `${object.y}%`,
                width: `${object.width}%`,
                objectFit: 'contain',
                zIndex: '8',
                padding: 0,
              }}
            >
                 <SVG
                  src={object.image}
                  style={{
                    width: '100%',
                    height: '100%',
                    cursor: 'pointer',
                    objectFit: 'contain',
                    color:
                      selectedColor
                        ? selectedColor
                        : object.initial_color,
                  }}

                  onClick={() => setSelectedColor(object.color)}
                />
</div>

if you mean the blue square for the dev tool now it's can't be change it will be always rectangular or square it just the area it takes of your screen all the thing inside this blue rectangle can be any shape you want in svg.如果您的意思是开发工具的蓝色正方形现在无法更改,它将始终是矩形或正方形,它只是您屏幕的面积这个蓝色矩形内的所有东西都可以是 svg 中您想要的任何形状。 for example: circle will still have blue square around them例如:圆圈周围仍然会有蓝色方块

You appear to be adding a click handler to the <svg> element.您似乎正在向<svg>元素添加点击处理程序。 The <svg> element has a rectangular shape. <svg>元素具有矩形形状。 Any clicks within that rectangle, will be captured by that click handler.该矩形内的任何点击都将被该点击处理程序捕获。

Is there a reason why you have one SVG for each rainbow band, and stack them on top of one another?是否有理由为每个彩虹乐队配备一个 SVG,并将它们堆叠在一起? It seems an odd way to do it.这似乎是一种奇怪的方式。

If you want clicks to be limited to the band, then apply the click handler to the <path> element that forms the band.如果您希望将点击限制在波段,则将点击处理程序应用于 forms 波段的<path>元素。

You will also find it much easier if you merge all the band <path> into one SVG.如果您将所有带<path>合并到一个 SVG 中,您还会发现它容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM