From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../canvasrenderingcontext2d/direction/index.html | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 files/zh-cn/web/api/canvasrenderingcontext2d/direction/index.html (limited to 'files/zh-cn/web/api/canvasrenderingcontext2d/direction/index.html') diff --git a/files/zh-cn/web/api/canvasrenderingcontext2d/direction/index.html b/files/zh-cn/web/api/canvasrenderingcontext2d/direction/index.html new file mode 100644 index 0000000000..32f4eb6d55 --- /dev/null +++ b/files/zh-cn/web/api/canvasrenderingcontext2d/direction/index.html @@ -0,0 +1,103 @@ +--- +title: CanvasRenderingContext2D.direction +slug: Web/API/CanvasRenderingContext2D/direction +tags: + - Canvas + - CanvasRenderingContext2D +translation_of: Web/API/CanvasRenderingContext2D/direction +--- +
{{APIRef}} {{SeeCompatTable}}
+ +

CanvasRenderingContext2D.direction 是Canvas 2D API 用来在绘制文本时,描述当前文本方向的属性。

+ +

语法

+ +
ctx.direction = "ltr" || "rtl" || "inherit";
+
+ +

选项

+ +

有效值:

+ +
+
ltr
+
文本方向从左向右。
+
rtl
+
文本方向从右向左。
+
inherit
+
根据情况继承 {{HTMLElement("canvas")}} 元素或者 {{domxref("Document")}} 。
+
+ +

默认值是inherit。

+ +

示例

+ +

使用direction 属性

+ +

这是一段简单的代码片段,对文本设置不同的direction数值。

+ +

HTML

+ +
<canvas id="canvas"></canvas>
+ +

JavaScript

+ +
var canvas = document.getElementById('canvas');
+var ctx = canvas.getContext('2d');
+
+ctx.font = '48px serif';
+ctx.fillText('Hi!', 150, 50);
+ctx.direction = 'rtl';
+ctx.fillText('Hi!', 150, 130);
+ + + + + +

结果

+ +

{{ EmbedLiveSample('Playable_code', 700, 180) }}

+ +

规范描述

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-direction", "CanvasRenderingContext2D.direction")}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ + + +

{{Compat("api.CanvasRenderingContext2D.direction")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf