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接口。