html text-stoke,HTML canvas strokeText()用法及代码示例

我们可以使用strokeText()方法在画布上绘制文本(不填充),本质上可以使用当前的font,lineWidth和strokeStyle属性在指定位置渲染指定文本,默认为文本颜色是黑色的。

用法:

context.strokeText(text, x, y, maxWidth);

参数值::此方法接受上面提到并在下面描述的四个参数:

text:此参数指定将要写在画布上的文本。

x:此参数指定相对于画布开始绘制文本的水平坐标。

y:此参数指定相对于画布开始绘制文本的垂直坐标。

maxWidth:此参数指定最大可能的文本宽度。

范例1:下面的示例说明了strokeTex()方法。

HTML canvas strokeText() Method

GeeksforGeeks

HTML canvas strokeText() Method

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

var ctx = c.getContext("2d");

ctx.font = "60px Arial";

ctx.strokeStyle = "green";

ctx.strokeText("GeeksforGeeks", 50, 50);

输出:

5e6c66e9192c0d0ec5d6f941887b4298.png

范例2:

HTML canvas strokeText() Method

GeeksforGeeks

HTML canvas strokeText() Method

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

var ctx = c.getContext("2d");

ctx.font = "60px Georgia";

ctx.strokeStyle = "blue";

ctx.strokeText("HTML Canvas", 60, 50);

输出:

a0d9454bf77d11fbffd29e0b46d1a69a.png

支持的浏览器:下面列出了HTML canvas strokeText()方法支持的浏览器:

谷歌浏览器

Internet Explorer 9.0

火狐浏览器

Opera

苹果浏览器

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值