HTML canvas lineWidth属性用于设置或返回线的宽度(线的厚度)。线的宽度以像素为单位设置。此属性的默认值为1。
用法:
context.lineWidth = number;
属性值:
number:该属性值指示以像素为单位指定线宽的数字。此属性忽略零,负,无穷和NaN值。
范例1:
HTML canvas lineWidth Property
GeeksforGeeks
HTML canvas lineWidth() Property
var canv = document.getElementById("canvas");
var context = canv.getContext("2d");
context.beginPath();
context.lineWidth = 20;
context.moveTo(40, 40);
context.lineTo(200, 150);
context.lineTo(40, 200);
context.strokeStyle = "green";
context.stroke();
输出:
程序2:
HTML canvas lineWidth Property
GeeksforGeeks
HTML canvas lineWidth() Property
var canv = document.getElementById("canvas");
var context = canv.getContext("2d");
context.beginPath();
context.lineWidth = 10;
context.strokeStyle ="green";
context.strokeRect(110, 40, 120, 100);
输出:
支持的浏览器:下面列出了HTML canvas lineWidth属性支持的浏览器:
谷歌浏览器
Internet Explorer 9.0
火狐浏览器
苹果浏览器
Opera