HTML canvas strokeStyle Property
Thí dụ
Vẽ một hình chữ nhật. Sử dụng một nét màu đỏ:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "#FF0000";
ctx.strokeRect(20, 20, 150, 100);
Hỗ trợ trình duyệt
Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ thuộc tính.
Property | |||||
---|---|---|---|---|---|
strokeStyle | Yes | 9.0 | Yes | Yes | Yes |
Định nghĩa và Cách sử dụng
Thuộc tính strokeStyle đặt hoặc trả về màu sắc, độ dốc hoặc mẫu được sử dụng cho các nét vẽ.
Giá trị mặc định: | # 000000 |
---|---|
Cú pháp JavaScript: | ngữ cảnh .strokeStyle = color | độ dốc | hoa văn ; |
Giá trị tài sản
Value | Description | Play it |
---|---|---|
color | A CSS color value that indicates the stroke color of the drawing. Default value is #000000 | |
gradient | A gradient object (linear or radial) used to create a gradient stroke | |
pattern | A pattern object used to create a pattern stroke |
Các ví dụ khác
Thí dụ
Vẽ một hình chữ nhật. Sử dụng một nét vẽ gradient:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var gradient = ctx.createLinearGradient(0, 0, 170, 0);
gradient.addColorStop("0", "magenta");
gradient.addColorStop("0.5" ,"blue");
gradient.addColorStop("1.0", "red");
// Fill with gradient
ctx.strokeStyle = gradient;
ctx.lineWidth = 5;
ctx.strokeRect(20, 20, 150, 100);
Thí dụ
Viết dòng chữ "Big smile!", Với một nét vẽ chuyển sắc:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Verdana";
// Create gradient
var gradient = ctx.createLinearGradient(0, 0, c.width, 0);
gradient.addColorStop("0", "magenta");
gradient.addColorStop("0.5", "blue");
gradient.addColorStop("1.0", "red");
// Fill with gradient
ctx.strokeStyle = gradient;
ctx.strokeText("Big smile!", 10, 50);
❮ Tham chiếu HTML Canvas