我正在开发一个使用 svg 移动/旋转/缩放功能的应用程序。我在 Laravel 中编写后端程序,而前端使用 html/css/javascript。我在网上看到折线可能具有某种三次方贝塞尔曲线。
现在我的问题是:多边形 svg 元素是否有可能具有与此 example 中的折线相同的立方贝塞尔曲线? ?
svg 的结构如下:
<svg>
<g data-type="track">
<polygon class="track" points="2588,851 2537,1157 1796,916 1117,723 0,382 40,80 816,314 1885,638 1887,634"></polygon>
<polygon class="track" points="114,19 73,0 17,497 46,485"></polygon>
</g>
</svg>
是否可以给多边形元素一个立方贝塞尔曲线,以便它可以创建一个流动的多边形而不是正方形的非圆 Angular 多边形?
最佳答案
我认为这里的一些回复有点令人困惑。
(is it) possible for a polygon svg element to have the same cubic-bezier to it as the polyline
简短的回答是否定的。 <polygon>
(和 <polyline>
)元素始终呈现为您提供的坐标之间的一系列直线段。无法自动使连接具有半径 - 就像 HTML border-radius
.如果这就是您要问的。
如果线条的笔画宽度较大,您可以选择将线条连接处的外 Angular 圆化。
.track {
fill: none;
stroke: black;
stroke-width: 20;
}
.round {
stroke-linejoin: round;
}
<svg width="300" height="300">
<polygon class="track" points="20,20 290,20 290,130 20,130"></polygon>
<polygon class="track round" points="20,170 290,170 290,280 20,280"></polygon>
</svg>
如果你想在你的“线”中包含贝塞尔曲线段,你将不得不使用 <path>
元素代替。正如您链接到的示例中所使用的那样。
关于javascript - Svg 多边形舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399897/