HTML कैनवास स्ट्रोकटेक्स्ट () विधि
उदाहरण
"हैलो वर्ल्ड!" लिखें और "बड़ी मुस्कान!" (ढाल के साथ) कैनवास पर, स्ट्रोकटेक्स्ट () का उपयोग करके:
जावास्क्रिप्ट:
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);
ब्राउज़र समर्थन
तालिका में संख्याएं पहले ब्राउज़र संस्करण को निर्दिष्ट करती हैं जो पूरी तरह से विधि का समर्थन करता है।
Method | |||||
---|---|---|---|---|---|
strokeText() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
नोट: मैक्सविड्थ पैरामीटर सफारी में समर्थित नहीं है।
परिभाषा और उपयोग
स्ट्रोकटेक्स्ट () विधि कैनवास पर टेक्स्ट (बिना भरण के) खींचती है। पाठ का डिफ़ॉल्ट रंग काला है।
युक्ति: फ़ॉन्ट और फ़ॉन्ट आकार निर्दिष्ट करने के लिए फ़ॉन्ट गुण का उपयोग करें , और किसी अन्य रंग/ग्रेडिएंट में पाठ को प्रस्तुत करने के लिए स्ट्रोक स्टाइल गुण का उपयोग करें।
जावास्क्रिप्ट सिंटैक्स: | संदर्भ । स्ट्रोकटेक्स्ट ( पाठ, एक्स, वाई, मैक्सविड्थ ); |
---|
पैरामीटर मान
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 |
❮ कैनवास वस्तु