HTML canvas translate() 方法
實例
在位置 (10,10) 處繪制一個矩形,將新的 (0,0) 位置設(shè)置為 (70,70)。再次繪制新的矩形(請注意現(xiàn)在矩形從位置 (80,80) 開始繪制):
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillRect(10,10,100,50);
ctx.translate(70,70);
ctx.fillRect(10,10,100,50);
var ctx=c.getContext("2d");
ctx.fillRect(10,10,100,50);
ctx.translate(70,70);
ctx.fillRect(10,10,100,50);
嘗試一下 ?
瀏覽器支持
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 translate()方法。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。
定義和用法
translate() 方法重新映射畫布上的 (0,0) 位置。
注意:當(dāng)您在 translate() 之后調(diào)用諸如 fillRect() 之類的方法時,值會添加到 x 和 y 坐標值上。

JavaScript 語法: | context.translate(x,y); |
---|
參數(shù)值
注意: You can specify one or both parameters.
參數(shù) | 描述 |
---|---|
x | 添加到水平坐標(x)上的值。 |
y | 添加到垂直坐標(y)上的值。 |

更多建議: