~james/core

core/web/src/lib/stuck.ts -rw-r--r-- 342 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
export const stuck = (node: HTMLElement) => {
	const observer = new IntersectionObserver(
		([entry]) =>
			node.toggleAttribute(
				"data-stuck",
				entry.intersectionRatio < 1 && entry.boundingClientRect.top < 1
			),
		{ rootMargin: "-1px 0px 0px 0px", threshold: 1 }
	);
	observer.observe(node);
	return () => observer.disconnect();
};