这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
Path2D()
constructor returns a newly instantiated
Path2D
object, optionally with another path as an argument (creates a copy), or optionally with a string consisting of
SVG path
数据。
new Path2D(); new Path2D(path); new Path2D(d);
path
可选
Path2D
object, a copy of the
path
argument is created.
d
可选
This example creates and copies a
Path2D
路径。
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let path1 = new Path2D();
path1.rect(10, 10, 100,100);
let path2 = new Path2D(path1);
path2.moveTo(220, 60);
path2.arc(170, 60, 50, 0, 2 * Math.PI);
ctx.stroke(path2);
此范例创建
Path2D
path using
SVG path data
. The path will move to point (
M10 10
) and then move horizontally 80 points to the right (
h 80
), then 80 points down (
v 80
), then 80 points to the left (
h -80
), and then back to the start (
Z
).
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
ctx.fill(p);
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'Path2D()' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Path2D
|
Chrome Yes | Edge ≤18 | Firefox 31 | IE ? | Opera Yes | Safari 10 | WebView Android Yes | Chrome Android Yes | Firefox Android 31 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
Path2D()
构造函数
|
Chrome Yes |
Edge
≤18
注意事项
|
Firefox 31 | IE ? | Opera Yes | Safari 10 | WebView Android 不支持 No | Chrome Android 42 | Firefox Android 31 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android 4.0 |
addPath
|
Chrome Yes | Edge ≤79 | Firefox 34 | IE 不支持 No | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 34 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
Path2D
, the interface this constructor belongs to