HTML 캔버스 strokeText () 메소드
예
"여보세요 세계"캔버스 텍스트를 작성하고, strokeText ()를 사용 (그라데이션)와 함께 "큰 미소를!"
자바 스크립트 :
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="20px Georgia";
ctx.strokeText("Hello World!",10,50);
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,90);
var ctx=c.getContext("2d");
ctx.font="20px Georgia";
ctx.strokeText("Hello World!",10,50);
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,90);
»시도
브라우저 지원
인터넷 익스플로러 9, 파이어 폭스, 오페라, 크롬과 사파리 지원 strokeText () 메소드.
참고 : 인터넷 익스플로러 8 이전 버전의 <캔버스> 요소를 지원하지 않습니다.
참고 : 사파리의 maxWidth 매개 변수를 지원하지 않습니다.
정의 및 사용
strokeText () 메소드는 캔버스 (아무 채우기 색)에 텍스트를 그립니다. 기본 텍스트 색은 검은 색입니다.
팁 : 사용 글꼴은 글꼴 및 글꼴 크기를 정의하고 사용하는 속성 strokeStyle 텍스트를 렌더링하기 위해 다른 색상 / 그라데이션에 속성을.
자바 스크립트 구문 : | 문맥 .strokeText (텍스트, X, Y,의 maxWidth); |
---|
매개 변수 값
参数 | 描述 |
---|---|
text | 规定在画布上输出的文本。 |
x | 开始绘制文本的 x 坐标位置(相对于画布)。 |
y | 开始绘制文本的 y 坐标位置(相对于画布)。 |
maxWidth | 可选。允许的最大文本宽度,以像素计。 |
HTML 캔버스 참조 설명서