ข้อมูลอ้างอิงHTML

HTML โดยตัวอักษร HTML ตามหมวดหมู่ รองรับ HTML Browser แอตทริบิวต์ HTML HTML Global Attributes เหตุการณ์ HTML HTML สี HTML Canvas HTML เสียง/วิดีโอ ชุดอักขระ HTML HTML Doctypes การเข้ารหัส URL HTML รหัสภาษา HTML รหัสประเทศ HTML ข้อความ HTTP วิธี HTTP ตัวแปลง PX เป็น EM แป้นพิมพ์ลัด


HTML canvas strokeStyle Property

❮ อ้างอิงผ้าใบ HTML

ตัวอย่าง

วาดรูปสี่เหลี่ยมผืนผ้า. ใช้สีเส้นขีดสีแดง:

YourbrowserdoesnotsupporttheHTML5canvastag.

จาวาสคริปต์:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "#FF0000";
ctx.strokeRect(20, 20, 150, 100);

รองรับเบราว์เซอร์

ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์

Property
strokeStyle Yes 9.0 Yes Yes Yes

ความหมายและการใช้งาน

คุณสมบัติ strokeStyle ตั้งค่าหรือส่งคืนสี การไล่ระดับสี หรือรูปแบบที่ใช้สำหรับลายเส้น

ค่าเริ่มต้น: #000000
ไวยากรณ์ JavaScript: บริบท .strokeStyle= สี | ไล่โทนสี | รูปแบบ ;

มูลค่าทรัพย์สิน

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  

ตัวอย่างเพิ่มเติม

ตัวอย่าง

วาดรูปสี่เหลี่ยมผืนผ้า. ใช้จังหวะการไล่ระดับสี:

YourbrowserdoesnotsupporttheHTML5canvastag.

จาวาสคริปต์:

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);

ตัวอย่าง

เขียนข้อความ "ยิ้มกว้าง!" ด้วยจังหวะการไล่ระดับสี:

YourbrowserdoesnotsupporttheHTML5canvastag.

จาวาสคริปต์:

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);

❮ อ้างอิงผ้าใบ HTML