English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
strokeText() ist eine Canvas 2D API zeichnet Text in der angegebenen (x, y)-Position. Wenn ein vierter Parameter als Maximalwert bereitgestellt wird, wird der Text skaliert, um die Breite anzupassen.
Verwenden Sie strokeText(), um Text "Grundtutorialsite!" und "de.oldtoolbag.com!" (mit Farbverlauf):
!DOCTYPE html> <html> <head> <meta charset="utf-8> <title>Verwendung des HTML canvas strokeText() Methoden-Grundtutorials(oldtoolbag.com)</title> </head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px fester #d3d3d3> Ihr Browser unterstützt keine HTML5 canvas-Tags. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.font="20px Georgia"; ctx.strokeText("Grundtutorialsite!",10,50); ctx.font="30px Verdana"; // Erstellen Sie einen Farbverlauf var gradient=ctx.createLinearGradient(0,0,c.width,0); gradient.addColorStop("0","Magenta"); gradient.addColorStop("0.5","blau"); gradient.addColorStop("1.0","rot"); // Füllen Sie eine Farbverlauf ctx.strokeStyle=gradient; ctx.strokeText("de.oldtoolbag.com!10,90); </script> </body> </html>Testen Sie, ob es funktioniert ‹/›
IEFirefoxOperChromeSafari
Internet Explorer 9,Firefox,Opera,Chrome and Safari support strokeText() Method.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
Note:Safari does not support the maxWidth parameter.
The strokeText() method draws text on the canvas (not filled). The default text color is black.
Hint:Please use font Properties to define the font and size, and use strokeStyle Properties in another color/Render text with gradients.
JavaScript Syntax: | context.strokeText(text,x,y,maxWidth); |
---|
Parameter | Description |
---|---|
text | The text to be output on the canvas. |
x | The x coordinate position where the text drawing starts (relative to the canvas). |
y | The y coordinate position where the text drawing starts (relative to the canvas). |
maxWidth | Optional. The maximum text width in pixels allowed. |