这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
CanvasRenderingContext2D
.direction
property of the Canvas 2D API specifies the current text direction used to draw text.
ctx.direction = "ltr" || "rtl" || "inherit";
可能的值:
"ltr"
The text direction is left-to-right.
"rtl"
The text direction is right-to-left.
"inherit"
<canvas>
element or the
Document
as appropriate. Default value.
默认值为
"inherit"
.
This example draws two pieces of text. The first one is left-to-right, and the second is right-to-left. Note that "Hi!" in
ltr
becomes "!Hi" in
rtl
.
<canvas id="canvas"></canvas>
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'CanvasRenderingContext2D.direction' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
direction
|
Chrome
Yes
Disabled
|
Edge
≤79
Disabled
|
Firefox No | IE No | Opera No | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android No | Opera Android No | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
CanvasRenderingContext2D
CanvasRenderingContext2D
addHitRegion()
arc()
arcTo()
beginPath()
bezierCurveTo()
clearHitRegions()
clearRect()
clip()
closePath()
createImageData()
createLinearGradient()
createPattern()
createRadialGradient()
drawFocusIfNeeded()
drawImage()
drawWidgetAsOnScreen()
drawWindow()
ellipse()
fill()
fillRect()
fillText()
getImageData()
getLineDash()
getTransform()
isPointInPath()
isPointInStroke()
lineTo()
measureText()
moveTo()
putImageData()
quadraticCurveTo()
rect()
removeHitRegion()
resetTransform()
restore()
rotate()
save()
scale()
scrollPathIntoView()
setLineDash()
setTransform()
stroke()
strokeRect()
strokeText()
transform()
translate()