Skip to content

Commit e037bdc

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # docs/Recipes.md
2 parents c6d1f48 + 1fe8907 commit e037bdc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/Recipes.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ Triggering animations once they enter the viewport is also a perfect use case
7979
for an IntersectionObserver.
8080

8181
- Set `triggerOnce`, to only trigger the animation the first time.
82-
- Use `margin` to offset the trigger points. It ensures that a fixed fixed
83-
amount is visible, regardless of the element size.
82+
- Set `threshold`, to control how much of the element should visible before
83+
firing the event.
84+
- Instead of `threshold`, you can use `rootMargin` to have a fixed amount be
85+
visible before triggering. Use a negative margin value, like `-100px 0`, to
86+
have it go inwards. You can also use a percentage value, instead of pixels.
8487

8588
```jsx
8689
import React from 'react'
@@ -89,7 +92,7 @@ import { useSpring, animated } from 'react-spring'
8992

9093
const LazyAnimation = () => {
9194
const [ref, inView] = useInView(ref, {
92-
margin: '-100px 0',
95+
rootMargin: '-100px 0',
9396
})
9497
const props = useSpring({ opacity: inView ? 1 : 0 })
9598

@@ -110,15 +113,18 @@ fire an event on your tracking service.
110113

111114
- Set `triggerOnce`, to only trigger an event the first time the element enters
112115
the viewport.
113-
- Use `margin` to offset the trigger points. It ensures that a fixed fixed
114-
amount is visible, regardless of the element size.
116+
- Set `threshold`, to control how much of the element should visible before
117+
firing the event.
118+
- Instead of `threshold`, you can use `rootMargin` to have a fixed amount be
119+
visible before triggering. Use a negative margin value, like `-100px 0`, to
120+
have it go inwards. You can also use a percentage value, instead of pixels.
115121

116122
```jsx
117123
import React, { useEffect } from 'react'
118124
import { useInView } from 'react-intersection-observer'
119125

120126
const TrackImpression = () => {
121-
const [ref, inView] = useInView({ triggerOnce: true, margin: '-100px 0' })
127+
const [ref, inView] = useInView({ triggerOnce: true, rootMargin: '-100px 0' })
122128
useEffect(() => {
123129
if (inView) {
124130
// Fire a tracking event to your tracking service of choice.

0 commit comments

Comments
 (0)