<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>设置线条的宽度lineWidth</title> <style> canvas{ border: 1px dashed gray } </style> <script> window.onload = function(){ var oCanvas = document.getElementById("canvas"); if(oCanvas.getContext){ var oContext = oCanvas.getContext("2d"); oContext.beginPath(); // 线条默认宽度是1 oContext.lineWidth = 10; oContext.moveTo(20,20); oContext.lineTo(200,20); oContext.stroke(); // 定义线帽样式lineCap // lineJoin定义两个线条交接处样式 // miterLimit设置或返回最大斜街长度 // setLineDash定义线条虚实样式-数组[线条的长度,间距,第二条的长度,第二条的间距] } } </script> </head> <body> <canvas id="canvas" width="250" height="250"></canvas> </body> </html>