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