A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/API/SVGTextContentElement/getCharNumAtPosition below:

SVGTextContentElement: getCharNumAtPosition() メソッド - Web API

SVGTextContentElement: getCharNumAtPosition() メソッド

Baseline Widely available

getCharNumAtPosition() は SVGTextContentElement インターフェイスのメソッドで、指定された座標の位置にテキストグリフがレンダリングされた文字を表します。文字とグリフの関係は一対一ではないため、関連するタイポグラフィ文字の最初の文字のみが返されます。

指定した位置で文字がみつからない場合は、 -1 が返されます。

構文
getCharNumAtPosition(point)
引数
point

DOMPoint オブジェクトです。ユーザー座標空間で文字の位置を調べる座標 (x, y) です。

返値

long 型です。位置に対応する文字のインデックス。

例 指定された位置の文字を探す
<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");

// DOMPoint を (30, 40) の位置で作成
const point = new DOMPoint(30, 40);

// 指定された位置の文字を取得
const charIndex = textElement.getCharNumAtPosition(point);

console.log(charIndex); // 出力: 2 (文字 "l")

// 文字が存在しない位置の点をチェック
const offPoint = new DOMPoint(300, 40);
const offCharIndex = textElement.getCharNumAtPosition(offPoint);

console.log(offCharIndex); // 出力: -1 (文字が見つからない)
仕様書 ブラウザーの互換性

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4