SVGTextContentElement: getCharNumAtPosition() Methode
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Die getCharNumAtPosition()
-Methode des SVGTextContentElement
Interfaces repräsentiert das Zeichen, das dazu führte, dass ein Textglyph an einer bestimmten Position im Koordinatensystem gerendert wurde. Da die Beziehung zwischen Zeichen und Glyphen nicht eins zu eins ist, wird nur das erste Zeichen des entsprechenden typografischen Zeichens zurückgegeben.
Wenn an der angegebenen Position kein Zeichen gefunden wird, wird -1
zurückgegeben.
Syntax
getCharNumAtPosition(point)
Parameter
Rückgabewert
Ein long; der Index des Zeichens, das der Position entspricht.
Beispiele
Finden des Zeichens an einer bestimmten Position
<svg width="200" height="100">
<text id="exampleText" x="10" y="40" font-size="16">Hello, SVG World!</text>
</svg>
const textElement = document.getElementById("exampleText");
// Create a DOMPoint for the position (30, 40)
const point = new DOMPoint(30, 40);
// Get the character at the specified position
const charIndex = textElement.getCharNumAtPosition(point);
console.log(charIndex); // Output: 2 (for character "l")
// Check with a point where no character is present
const offPoint = new DOMPoint(300, 40);
const offCharIndex = textElement.getCharNumAtPosition(offPoint);
console.log(offCharIndex); // Output: -1 (no character found)
Spezifikationen
Specification |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGTextContentElement__getCharNumAtPosition |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getCharNumAtPosition |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support