UNPKG

@threlte/extras

Version:

Utilities, abstractions and plugins for your Threlte apps

18 lines (17 loc) 544 B
import { observe } from '@threlte/core'; export class OffscreenObserver { isOffscreen = $state(false); constructor(getElement) { observe(() => [getElement()], ([element]) => { const observer = new IntersectionObserver((entries) => { for (const entry of entries) { this.isOffscreen = !entry.isIntersecting; } }); observer.observe(element); return () => { observer.disconnect(); }; }); } }