html5 stroke,HTML canvas strokeRect()用法及代码示例

strokeRect()方法用于以给定颜色绘制矩形。笔划的默认颜色是黑色。

用法:

context.strokeRect(x, y, width, height)

参数:

x:它存储矩形左上角的x坐标。

y:它存储矩形左上角的y坐标。

width:它以像素为单位存储宽度。

height:它以像素为单位存储高度。

示例1:

HTML canvas strokeRect() Method

width="500"

height="300">

var x =

document.getElementById("GFG");

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

contex.strokeRect(50, 50, 350, 200);

contex.stroke();

输出:

ab7d2b81ecd55b599f7db45070950a94.png

示例2:

HTML canvas

strokeRect() Method

width="500"

height="300">

var x =

document.getElementById("GFG");

var contex =

x.getContext("2d");

contex.strokeStyle = "green";

contex.strokeRect(50, 50, 350, 200);

contex.strokeStyle = "red";

contex.strokeRect(100, 100, 250, 100);

contex.stroke();

输出:

05ef16c98c4ae90b72d10268cbe70d9c.png

支持的浏览器:

谷歌浏览器

Internet Explorer 9.0

火狐浏览器

苹果浏览器

Opera

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值