14 lines
414 B
TypeScript
14 lines
414 B
TypeScript
/** Reactive `window.scrollY > threshold`, evaluated after mount (passive listener). */
|
|||
|
|
export function useScrolledPast(threshold: number) {
|
||
|
|
const past = ref(false);
|
||
|
|
const on = () => (past.value = window.scrollY > threshold);
|
||
|
|
|
||
|
|
onMounted(() => {
|
||
|
|
on();
|
||
|
|
window.addEventListener("scroll", on, { passive: true });
|
||
|
|
});
|
||
|
|
onBeforeUnmount(() => window.removeEventListener("scroll", on));
|
||
|
|
|
||
|
|
return past;
|
||
|
|
}
|