Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-cn]: update the translation of CanvasRenderingContext2D.beginPath() method #21982

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions files/zh-cn/web/api/canvasrenderingcontext2d/beginpath/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
---
title: CanvasRenderingContext2D.beginPath()
tianyeeT marked this conversation as resolved.
Show resolved Hide resolved
slug: Web/API/CanvasRenderingContext2D/beginPath
l10n:
sourceCommit: af1e384356e21dbcc573d1c1cc015ec79c644de1
tianyeeT marked this conversation as resolved.
Show resolved Hide resolved
---

{{APIRef}}

**`CanvasRenderingContext2D.beginPath()`** 是 Canvas 2D API 通过清空子路径列表开始一个新路径的方法。当你想创建一个新的路径时,调用此方法。
Canvas 2D API 的 **`CanvasRenderingContext2D.beginPath()`** 方法用于通过清空子路径列表开始一个新路径。当你想创建一个新的路径时,调用此方法。

> **备注:** 要创建一个新的子路径,即与当前画布状态匹配的路径,可以使用 {{domxref("CanvasRenderingContext2D.moveTo()")}}。

## 语法

```js-nolint
beginPath()
```
void ctx.beginPath();
```

### 参数

无。

### 返回值

无({{jsxref("undefined")}})。

## 示例

Expand All @@ -27,18 +39,20 @@ void ctx.beginPath();

#### JavaScript

`beginPath()` 方法在开始每条线之前调用,以便它们可以用不同的颜色绘制。

```js
const canvas = document.getElementById("canvas");
const 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);
Expand All @@ -60,5 +74,5 @@ ctx.stroke();

## 参见

- 接口定义, {{domxref("CanvasRenderingContext2D")}}
- 定义此方法的接口:{{domxref("CanvasRenderingContext2D")}}
- {{domxref("CanvasRenderingContext2D.closePath()")}}