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

javascriptngữ cảnh.lineJoin = 'miter' hoặc 'round' hoặc 'bevel';

Ví dụ

Đặt thuộc tính lineJoin thành giá trị miter:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet 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:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet 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:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet 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ẻ