strokeText()メソッドキャンバスHTML
例
使用strokeText()、キャンバスのテキストに書いて、 "ビッグスマイル!」(勾配付き)で" Hello world! ":
JavaScriptを:
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);
»をお試しください
ブラウザのサポート
Internet Explorer 9の、Firefoxの、オペラ、ChromeとSafariのサポートstrokeText()メソッド。
注:のInternet Explorer 8およびそれ以前のバージョンでは、<キャンバス>要素をサポートしていません。
注意:Safariは maxWidthにパラメータをサポートしていません。
定義と使用法
strokeText()メソッドは、キャンバス(なし塗りつぶしの色)にテキストを描画します。 デフォルトのテキストの色は黒です。
ヒント:使用したフォントは 、フォントおよびフォントサイズを定義し、使用する属性strokeStyleテキストをレンダリングするために別の色/グラデーションにプロパティを。
JavaScriptシンタックス: | コンテキスト.strokeText(テキスト、X、Y、のmaxWidth); |
---|
パラメータ値
参数 | 描述 |
---|---|
text | 规定在画布上输出的文本。 |
x | 开始绘制文本的 x 坐标位置(相对于画布)。 |
y | 开始绘制文本的 y 坐标位置(相对于画布)。 |
maxWidth | 可选。允许的最大文本宽度,以像素计。 |
HTMLキャンバスリファレンスマニュアル