CanvasRenderingContext2D.beginPath()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
El método CanvasRenderingContext2D.beginPath()
del API Canvas 2D comienza una nueva ruta vaciando la lista de sub-rutas. Invoca este método cuando quieras crear una nueva ruta.
Sintaxis
void ctx.beginPath();
Ejemplos
Usando el método beginPath
Este es solo un trozo de código el cual usa el método beginPath
.
HTML
html
<canvas id="canvas"></canvas>
JavaScript
js
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
// First path
ctx.beginPath();
ctx.strokeStyle = "blue";
ctx.moveTo(20, 20);
ctx.lineTo(200, 20);
ctx.stroke();
// Second path
ctx.beginPath();
ctx.strokeStyle = "green";
ctx.moveTo(20, 20);
ctx.lineTo(120, 120);
ctx.stroke();
Edita el código aquí debajo y mira tus cambios actualizarse en vivo en el canvas:
Especificaciones
Specification |
---|
HTML # dom-context-2d-beginpath-dev |
Compatibilidad con navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
beginPath |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Ver también
- The interface defining it,
CanvasRenderingContext2D
CanvasRenderingContext2D.closePath()