跳过主要内容

DrawSVGPlugin.getLength

DrawSVGPlugin.getLength(element:[Element | Selector text]): Number

提供一种简便的方法获取 SVG 元素描边的长度,包括:<path>, <rect>, <circle>, <ellipse>, <line>, <polyline>,以及<polygon>

参数

  • 元素:[元素 | 选择器文本]

    你想要确定其描边长度的元素(或该元素的选择器文本)。

返回值 : 数值

SVG元素描边的长度。

细节

提供一种简便的方法获取 SVG 元素描边的长度,包括:<path>, <rect>, <circle>, <ellipse>, <line>, <polyline>,以及<polygon>.

当与位置结合使用时(通过以下方式获取DrawSVGPlugin.getPosition),你可以在任何给定时刻像这样计算总百分比:

function getPercentage(element) {
return Math.floor(
DrawSVGPlugin.getPosition(element)[1] /
(DrawSVGPlugin.getLength(element) / 100)
);
}
无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗