HTML translate方法,HTML canvas translate()用法及代码示例

HTML canvas translate()方法用于指定对象以给定的转换量进行转换。

用法:

context.translate(x, y)

参数值:

x:它存储值,即画布将向左或向右移动多少表示x轴方向。

y:它存储值,即画布将上下移动多少意味着y轴方向。

范例1:您可以在此处通过更改x轴和y轴进行检查。

HTML canvas translate() Method

GeeksforGeeks

style="border:2px solid gray">

var geeks = document.getElementById("GFG");

var contex = geeks.getContext("2d");

contex.translate(250, 110); //contex.translate(x, y);

contex.fillStyle = "#00FF00";

contex.fillRect(20, 20, 150, 100);

输出:

93ce760cd04fc1f456561af874183c6c.png

范例2:

HTML canvas translate() Method

GeeksforGeeks

style="border:2px solid gray">

var geeks = document.getElementById("GFG");

var contex = geeks.getContext("2d");

contex.rect(00, 00, 150, 100);

contex.fillStyle = "green";

contex.fill();

contex.stroke();

contex.translate(250, 50);

contex.rect(100, 100, 150, 100);

contex.fillStyle = "";

contex.fill();

contex.stroke();

输出:

0bd5f166bd6d0372ff3563728105bde3.png

注意:如果在translate()方法之后调用fillRect()方法,则该值将添加到x和y坐标值中。

支持的浏览器:

谷歌浏览器

Internet Explorer 9.0或以上

火狐浏览器

苹果浏览器

Opera

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值