a tool for shared writing and social publishing
1export async function isVisible(el: Element) {
2 return new Promise<boolean>((resolve) => {
3 const observer = new IntersectionObserver(
4 (entries, observer) => {
5 entries.forEach((entry) => {
6 resolve(entry.isIntersecting);
7 observer.unobserve(entry.target);
8 });
9 },
10 {
11 root: null, // Use the viewport as the root
12 threshold: 0.1, // Trigger when 10% of the element is visible
13 },
14 );
15
16 observer.observe(el);
17 });
18}