demo.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<canvas id="cvs" width="500" height="500"></canvas>
<script>
var cvs = document.getElementById('cvs');
var ctx = cvs.getContext('2d');
/*
* 设置线帽样式:
* ctx.lineCap = 'butt' 、'round'、'square'
* butt是默认值,
* round线头是圆的,
* square线头两端各增加线宽的一半。
* */
ctx.lineWidth = 10;
// 默认线头
ctx.moveTo( 10, 10 );
ctx.lineTo( 310, 10 );
ctx.stroke();
// 圆线头,两端的圆半径为线宽的一半
ctx.beginPath();
ctx.lineCap = 'round';