HTML 캔버스 strokeStyle 속성
예시
직사각형을 그립니다. 빨간색의 획 색상 사용:
자바스크립트:
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 |
---|---|
자바스크립트 구문: | 컨텍스트 .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 |
더 많은 예
예시
직사각형을 그립니다. 그라디언트 획 사용:
자바스크립트:
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);
예시
그라데이션 획으로 "큰 미소!"라는 텍스트를 작성합니다.
자바스크립트:
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 캔버스 참조