Phương thức canvas strokeRect () HTML

❮ Tham chiếu HTML Canvas

Thí dụ

Vẽ hình chữ nhật 150 * 100 pixel:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
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 đủ phương pháp này.

Method
strokeRect() Yes 9.0 Yes Yes Yes

Định nghĩa và Cách sử dụng

Phương thức strokeRect () vẽ một hình chữ nhật (không tô màu). Màu mặc định của nét vẽ là màu đen.

Mẹo: Sử dụng thuộc tính strokeStyle để đặt màu, gradient hoặc mẫu để tạo kiểu cho nét.

Cú pháp JavaScript: context .strokeRect ( x, y, width, height );

Giá trị tham số

Parameter Description Play it
x The x-coordinate of the upper-left corner of the rectangle
y The y-coordinate of the upper-left corner of the rectangle
width The width of the rectangle, in pixels
height The height of the rectangle, in pixels

❮ Tham chiếu HTML Canvas