You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|**root**| Element | document | false | The IntersectionObserver interface's read-only root property identifies the Element or Document whose bounds are treated as the bounding box of the viewport for the element which is the observer's target. If the root is null, then the bounds of the actual document viewport are used. |
150
-
|**rootMargin**| string | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
151
-
|**threshold**| number \| number[]| 0 | false | Number between 0 and 1 indicating the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
152
-
|**skip**| boolean | false | false | Skip creating the IntersectionObserver. You can use this to enable and disable the observer as needed. If `skip` is set while `inView`, the current state will still be kept. |
153
-
|**triggerOnce**| boolean | false | false | Only trigger this method once. |
146
+
| Name | Type | Default | Required | Description |
|**root**| Element | document | false | The IntersectionObserver interface's read-only root property identifies the Element or Document whose bounds are treated as the bounding box of the viewport for the element which is the observer's target. If the root is null, then the bounds of the actual document viewport are used. |
149
+
|**rootMargin**| string | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
150
+
|**threshold**| number \| number[]| 0 | false | Number between 0 and 1 indicating the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
151
+
|**trackVisibility** 🧪 | boolean | false | false | A boolean indicating whether this IntersectionObserver will track changes in a target’s visibility. |
152
+
|**delay** 🧪 | number | undefined | false | A number indicating the minimum delay in milliseconds between notifications from this observer for a given target. This must be set to at least `100` if `trackVisibility` is `true`. |
153
+
|**skip**| boolean | false | false | Skip creating the IntersectionObserver. You can use this to enable and disable the observer as needed. If `skip` is set while `inView`, the current state will still be kept. |
154
+
|**triggerOnce**| boolean | false | false | Only trigger the observer once. |
154
155
155
156
> ⚠️ When passing an array to `threshold`, store the array in a constant to
156
157
> avoid the component re-rendering too often. For example:
157
158
158
-
```js
159
+
```jsx
159
160
constTHRESHOLD= [0.25, 0.5, 0.75]; // Store multiple thresholds in a constant
@@ -177,6 +178,29 @@ The **`<InView />`** component also accepts the following props:
177
178
|**children**|`({ref, inView, entry}) => React.ReactNode`, `ReactNode`|| true | Children expects a function that receives an object containing the `inView` boolean and a `ref` that should be assigned to the element root. Alternatively pass a plain child, to have the `<InView />` deal with the wrapping element. You will also get the `IntersectionObserverEntry` as `entry, giving you more details. |
178
179
|**onChange**|`(inView, entry) => void`|| false | Call this function whenever the in view state changes. It will receive the `inView` boolean, alongside the current `IntersectionObserverEntry`. |
179
180
181
+
### IntersectionObserver v2 🧪
182
+
183
+
The new
184
+
[v2 implementation of IntersectionObserver](https://developers.google.com/web/updates/2019/02/intersectionobserver-v2)
185
+
extends the original API, so you can track if the element is covered by another
186
+
element or has filters applied to it. Useful for blocking clickjacking attempts
187
+
or tracking ad exposure.
188
+
189
+
To use it, you'll need to add the new `trackVisibility` and `delay` options.
190
+
When you get the `entry` back, you can then monitor if `isVisible` is `true`.
0 commit comments