EditContext: characterBounds() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

EditContext 介面的 characterBounds() 方法返回一個包含 EditContext 物件中字元邊界矩形列表的 Array

作業系統使用 EditContext 物件中字元的位置和大小,以在需要時正確地定位特定於平臺的編輯相關 UI 表面,例如 輸入法編輯器 (IME) 視窗。這在作業系統無法自動檢測字元位置和大小時尤其重要,例如在 <canvas> 元素中渲染文字時。

Web 開發者最可能感興趣的是結合使用 characterboundsupdate 事件和 EditContext.updateCharacterBounds() 方法,以便在作業系統指示需要字元位置和大小資訊時更新字元邊界。

characterBounds() 方法返回使用 updateCharacterBounds() 最後更新的字元邊界列表。該列表不包含 EditContext 物件中每個字元的條目,只包含使用 updateCharacterBounds() 更新的字元。要了解字元在 EditContext 物件中的位置,請使用 EditContext.characterBoundsRangeStart 屬性。

語法

js
characterBounds()

引數

無。

返回值

包含 DOMRect 物件的 Array

規範

規範
EditContext API
# dom-editcontext-characterbounds

瀏覽器相容性

另見