<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>canvas描边样式-setLineDash</title>
<style>
html{height: 100%;overflow: hidden;}
body{height: 100%;margin: 0;}
#test{
background: antiquewhite;
}
</style>
</head>
<body>
<canvas id="test"></canvas>
<script>
const cvs=document.getElementById('test');
cvs.width=window.innerWidth;
cvs.height=window.innerHeight;
const ctx=cvs.getContext('2d');
/*strokeStyle:描边的着色样式*/
ctx.strokeStyle='maroon';
/*lineWidth:描边宽*/
ctx.lineWidth=4;
/* setLineDash(segments) 虚线 */
ctx.save();
ctx.setLineDash([30,60,90]);
ctx.beginPath();
ctx.moveTo(50,100);
ctx.lineTo(700,100);
ctx.stroke();
ctx.restore();
</script>
</body>
</html>