textBaseline गुण
textBaseline गुण
fillText विधि
या strokeText विधि
का उपयोग करके बनाए गए टेक्स्ट का वर्टिकल अलाइनमेंट सेट करता है।
संभावित मानों में से एक स्वीकार करता है: top,
hanging, middle, alphabetic (डिफ़ॉल्ट रूप से),
ideographic, bottom (मानों को समझने के लिए
देखें www.w3schools.com/tags/canvas_textbaseline.asp)।
सिंटैक्स
context.textBaseline = value;
उदाहरण
आइए टेक्स्ट को ऊपरी लाइन के अनुसार वर्टिकल अलाइनमेंट सेट करें:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline = 'top';
ctx.fillText('text', 80, 100);
:
उदाहरण
और अब आइए टेक्स्ट को निचली लाइन के अनुसार वर्टिकल अलाइनमेंट सेट करें:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline="bottom";
ctx.fillText('text', 80, 100);
: