SVGPathElement: getPathSegmentAtLength() 方法
getPathSegmentAtLength() 方法屬於 SVGPathElement 介面,它返回路徑上指定距離處的路徑段。
語法
js
getPathSegmentAtLength(distance)
引數
distance-
指示路徑上距離的數字。
返回值
一個路徑段物件。如果沒有有效的段,則返回 null。
Segment 物件具有以下屬性
示例
獲取路徑段
考慮以下繪製正方形的 <path> 元素:
xml
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64">
<path d="M0,0 h64 v64 h-64 z" />
</svg>
getPathSegmentAtLength() 方法將返回一個物件,該物件表示路徑上距離 65px 處的 v64 段。
js
const path = document.querySelector("path");
console.log(path.getPathSegmentAtLength(65));
// Output: path segment
// {
// type: "v",
// values: [64]
// }
規範
| 規範 |
|---|
| SVG 路徑 # __svg__SVGPathElement__getPathSegmentAtLength |
瀏覽器相容性
載入中…