EditContext:updateControlBounds() 方法
EditContext 介面的 EditContext.updateControlBounds() 方法用於將可編輯文字區域的位置和大小資訊通知作業系統。
呼叫此方法可告知作業系統當前可編輯區域的邊界。您應該在初始化 EditContext 時以及每當可編輯區域的邊界發生變化時(例如網頁大小調整時)呼叫此方法。這些邊界用於定位平臺特定的、與編輯相關的 UI 表面,例如 輸入法編輯器 (IME) 視窗。
語法
js
updateControlBounds(controlBounds)
引數
controlBounds-
一個表示新控制元件邊界的
DOMRect物件。
返回值
無 (undefined)。
異常
示例
在編輯器初始化和視窗大小調整時更新控制元件邊界
此示例展示瞭如何使用 updateControlBounds() 方法隨時告知平臺可編輯區域的位置。
css
#editor {
border: 1px solid black;
height: 50vw;
width: 50vh;
}
html
<div id="editor"></div>
js
const editorEl = document.getElementById("editor");
const editContext = new EditContext();
editorEl.editContext = editContext;
function updateControlBounds() {
const editorBounds = editorEl.getBoundingClientRect();
editContext.updateControlBounds(editorBounds);
console.log(
`Updated control bounds to ${editorBounds.x}, ${editorBounds.y}, ${editorBounds.width}, ${editorBounds.height}`,
);
}
// Update the control bounds now.
updateControlBounds();
// And when the page is resized.
window.addEventListener("resize", updateControlBounds);
規範
| 規範 |
|---|
| EditContext API # dom-editcontext-updatecontrolbounds |
瀏覽器相容性
載入中…
另見
- 它所屬的
EditContext介面。