chore: adjust useVisibilityChange
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
export const inBrowser = typeof window !== 'undefined';
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Ref, unref } from 'vue';
|
import { Ref, unref } from 'vue';
|
||||||
import { inBrowser, useEventListener } from '../useEventListener';
|
import { inBrowser } from '../shared';
|
||||||
|
import { useEventListener } from '../useEventListener';
|
||||||
|
|
||||||
export type UseClickAwayOptions = {
|
export type UseClickAwayOptions = {
|
||||||
eventName?: string;
|
eventName?: string;
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import {
|
|||||||
onUnmounted,
|
onUnmounted,
|
||||||
onDeactivated,
|
onDeactivated,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
import { inBrowser } from '../shared';
|
||||||
export const inBrowser = typeof window !== 'undefined';
|
|
||||||
|
|
||||||
let supportsPassive = false;
|
let supportsPassive = false;
|
||||||
if (inBrowser) {
|
if (inBrowser) {
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import {
|
|||||||
onBeforeUnmount,
|
onBeforeUnmount,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
|
// @Experimental
|
||||||
export function useVisibilityChange(
|
export function useVisibilityChange(
|
||||||
target: Ref<Element>,
|
target: Ref<Element>,
|
||||||
onChange: () => void
|
onChange: (visible: boolean) => void
|
||||||
) {
|
) {
|
||||||
// compatibility: https://caniuse.com/#feat=intersectionobserver
|
// compatibility: https://caniuse.com/#feat=intersectionobserver
|
||||||
if (!inBrowser || !window.IntersectionObserver) {
|
if (!inBrowser || !window.IntersectionObserver) {
|
||||||
@@ -19,9 +20,7 @@ export function useVisibilityChange(
|
|||||||
const observer = new IntersectionObserver(
|
const observer = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
// visibility changed
|
// visibility changed
|
||||||
if (entries[0].intersectionRatio > 0) {
|
onChange(entries[0].intersectionRatio > 0);
|
||||||
onChange();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ root: document.body }
|
{ root: document.body }
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user