Published
Edited
Mar 3, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
html`
${rangeRects.map(
(rangeRect) => html`
<div style="
display: block;
position: absolute;
left: ${rangeRect.x}px;
top: ${rangeRect.y}px;
width: ${rangeRect.width}px;
height: ${rangeRect.height}px;
background: #6af;
z-index: -1;
"> </div>`
)}
${theDiv}
`
Insert cell
theDiv = {
let d = document.createElement("div");
d.textContent =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est.";
return d;
}
Insert cell
textNode = theDiv.childNodes[0]
Insert cell
range = {
let range = document.createRange();
range.setStart(textNode, start);
range.setEnd(textNode, end);
return range;
}
Insert cell
rangeRects = {
let offsetRect = theDiv.getClientRects()[0];
let rv = [];
for (const rect of range.getClientRects()) {
rv.push({
x: rect.x - offsetRect.x,
y: rect.y - offsetRect.y,
width: rect.width,
height: rect.height
});
}
return rv;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more