File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
files/en-us/web/api/svgpathelement Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " SVGPathElement: getPathSegmentAtLength() method"
3
+ short-title : getPathSegmentAtLength()
4
+ slug : Web/API/SVGPathElement/getPathSegmentAtLength
5
+ page-type : web-api-instance-method
6
+ browser-compat : api.SVGPathElement.getPathSegmentAtLength
7
+ ---
8
+
9
+ {{APIRef("SVG")}}
10
+
11
+ The ** ` SVGPathElement.getPathSegmentAtLength() ` ** method returns the segment at a given distance along the path.
12
+
13
+ ## Syntax
14
+
15
+ ``` js-nolint
16
+ getPathSegmentAtLength(distance)
17
+ ```
18
+
19
+ ### Parameters
20
+
21
+ - ` distance `
22
+
23
+ - : A float referring to the distance along the path.
24
+
25
+ ### Return value
26
+
27
+ A path segment object. If no valid segment exists, returns null.
28
+
29
+ Segment object has the following properties:
30
+
31
+ - ` type `
32
+ - : A [ path commands] ( /en-US/docs/Web/SVG/Reference/Attribute/d#path_commands ) .
33
+ - ` values `
34
+ - : An array or value containing the parameters for the corresponding command.
35
+
36
+ ## Examples
37
+
38
+ ### Get path segment
39
+
40
+ Consider the following ` <path> ` element, drawing a square:
41
+
42
+ ``` xml
43
+ <svg xmlns =" http://www.w3.org/2000/svg" width =" 64" height =" 64" >
44
+ <path d =" M0,0 h64 v64 h-64 z" />
45
+ </svg >
46
+ ```
47
+
48
+ The ` getPathSegmentAtLength() ` method will return an object that represents the ` v64 ` segment that lays 65px along the path:
49
+
50
+ ``` js
51
+ const path = document .querySelector (" path" );
52
+
53
+ console .log (path .getPathSegmentAtLength (65 ));
54
+
55
+ // Output: path segment
56
+ // {
57
+ // type: "v",
58
+ // values: [64]
59
+ // }
60
+ ```
61
+
62
+ ## Specifications
63
+
64
+ {{Specifications}}
65
+
66
+ ## Browser compatibility
67
+
68
+ {{Compat}}
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ _This interface also inherits methods from its parent, {{domxref("SVGGeometryEle
33
33
- : Returns the user agent's computed value for the total length of the path in user units.
34
34
- {{domxref("SVGPathElement.setPathData()")}} {{experimental_inline}}
35
35
- : Sets the sequence of path segments as the new path data.
36
+ - {{domxref("SVGPathElement.getPathSegmentAtLength()")}}
37
+ - : Returns the segment at a given distance along the path.
36
38
37
39
### Deprecated methods
38
40
You can’t perform that action at this time.
0 commit comments