Use ResizeObserver to detect changes in the size of .article-content

This code is for handling changes in position caused by content rendered as part of post-processing, such as Mermaid diagrams
This commit is contained in:
Jerry Kim 2024-12-24 12:52:05 +09:00
parent 087989e427
commit d166b24d59

View File

@ -125,6 +125,15 @@ function setupScrollspy() {
scrollHandler();
}
// Use ResizeObserver to detect changes in the size of .article-content
const articleContent = document.querySelector(".article-content");
if (articleContent) {
const resizeObserver = new ResizeObserver(() => {
resizeHandler();
});
resizeObserver.observe(articleContent);
}
window.addEventListener("resize", debounced(resizeHandler));
}