Bug 42799: Replace IntersectionObserver with scroll listener for sticky behaviour
Assisted-by: Mistral Vibe <vibe@mistral.ai> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
74b820394d
commit
35d4eebbb0
|
|
@ -78,20 +78,13 @@ function togglePanel(node) {
|
|||
function apply_sticky(node) {
|
||||
if (!node) return;
|
||||
|
||||
let sentinel = node.previousElementSibling;
|
||||
const onScroll = () => {
|
||||
const rect = node.getBoundingClientRect();
|
||||
node.classList.toggle("floating", rect.top <= 0);
|
||||
};
|
||||
|
||||
if (!sentinel || !sentinel.classList.contains("sticky-sentinel")) {
|
||||
sentinel = document.createElement("div");
|
||||
sentinel.className = "sticky-sentinel";
|
||||
|
||||
node.parentNode.insertBefore(sentinel, node);
|
||||
}
|
||||
|
||||
const observer = new IntersectionObserver(([entry]) => {
|
||||
node.classList.toggle("floating", !entry.isIntersecting);
|
||||
});
|
||||
|
||||
observer.observe(sentinel);
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
onScroll();
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue