Thuộc tính lineJoin
Thuộc tính lineJoin xác định cách thức nối
hai đường thẳng. Có thể nhận các giá trị sau:
miter - góc nhọn (mặc định),
round - góc tròn, bevel
- góc vát.
Cú pháp
ngữ cảnh.lineJoin = 'miter' hoặc 'round' hoặc 'bevel';
Ví dụ
Đặt thuộc tính lineJoin thành giá trị miter:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'miter';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();
:
Ví dụ
Đặt thuộc tính lineJoin thành giá trị round:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'round';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();
:
Ví dụ
Đặt thuộc tính lineJoin thành giá trị bevel:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'bevel';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();
:
Xem thêm
-
thuộc tính
miterLimit,
giới hạn chiều dài của góc nhọn -
thuộc tính
lineCap,
xác định kiểu đầu mút của đường kẻ