HTML कैनवास भरण पाठ () विधि
उदाहरण
"हैलो वर्ल्ड!" लिखें और "बड़ी मुस्कान!" (ढाल के साथ) कैनवास पर, fillText() का उपयोग करके:
जावास्क्रिप्ट:
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);
ब्राउज़र समर्थन
तालिका में संख्याएं पहले ब्राउज़र संस्करण को निर्दिष्ट करती हैं जो पूरी तरह से विधि का समर्थन करता है।
Method | |||||
---|---|---|---|---|---|
fillText() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
परिभाषा और उपयोग
भरण पाठ () विधि कैनवास पर भरे हुए पाठ को खींचती है। पाठ का डिफ़ॉल्ट रंग काला है।
युक्ति: फ़ॉन्ट और फ़ॉन्ट आकार निर्दिष्ट करने के लिए फ़ॉन्ट गुण का उपयोग करें , और पाठ को किसी अन्य रंग/ग्रेडिएंट में रेंडर करने के लिए fillStyle गुण का उपयोग करें।
जावास्क्रिप्ट सिंटैक्स: | संदर्भ .fillText ( पाठ, x, y, maxWidth ); |
---|
पैरामीटर मान
Parameter | Description | Play it |
---|---|---|
text | Specifies the text that will be written on the canvas | |
x | The x coordinate where to start painting the text (relative to the canvas) | |
y | The y coordinate where to start painting the text (relative to the canvas) | |
maxWidth | Optional. The maximum allowed width of the text, in pixels |
❮ कैनवास वस्तु