#editor {
border: 1px solid black;
height: 50vw;
width: 50vh;
}EditContext: updateControlBounds() method / notebook
EditContext: updateControlBounds() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<div id="editor"></div>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);