motion-v
Version:
<h1 align="center"> <img width="35" height="35" alt="Motion logo" src="https://github.com/user-attachments/assets/00d6d1c3-72c4-4c2f-a664-69da13182ffc" /><br />Motion for Vue</h1>
17 lines (16 loc) • 482 B
JavaScript
import { onMounted, onUnmounted, ref } from "vue";
function usePageInView() {
const isInView = ref(true);
const handleVisibilityChange = () => {
isInView.value = !document.hidden;
};
onMounted(() => {
if (document.hidden) handleVisibilityChange();
document.addEventListener("visibilitychange", handleVisibilityChange);
});
onUnmounted(() => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
});
return isInView;
}
export { usePageInView };