Skip to content

Commit 2ec1f3e

Browse files
SeanDempsfpapado
authored andcommitted
Expose margin and threshold in Readme (#21)
* expose margin and threshold * update readme * remove unnecessarily exposed props * remove unnecessary curly braces
1 parent a1c2235 commit 2ec1f3e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,32 @@ Any of the presentational patterns presented that are possible with `LazyImage`
209209

210210
In fact, if you check [`src/LazyImage.tsx`](./src/LazyImage.tsx), you will see that `LazyImage` is implemented in terms of `LazyImageFull`!
211211

212+
### Load ahead and threshold
213+
214+
Further control over the Intersection Observer can be provided through the `observerProps` prop object:
215+
216+
```jsx
217+
import { LazyImage } from "react-lazy-images";
218+
219+
<LazyImage
220+
src="/img/porto_buildings_large.jpg"
221+
alt="Buildings with tiled exteriors, lit by the sunset."
222+
placeholder={/* the usual */}
223+
actual={/* the usual */}
224+
observerProps={{
225+
rootMargin: "100px 0",
226+
threshold: 0.3
227+
}}
228+
/>;
229+
```
230+
231+
`rootMargin`: Margin around the window. This can have values similar to the CSS margin property, e.g. `"10px 20px 30px 40px"` (top, right, bottom, left) (defaulted to `"50px 0px"`)
232+
This can provide control if you want to request your image a certain number of pixels ahead of where the user is scrolling.
233+
234+
`threshold`: Number between 0 and 1 indicating the percentage that should be visible before a request is sent. (defaulted to `0.01`)
235+
236+
(See https://github.com/thebuilder/react-intersection-observer#api)
237+
212238
### Load before swap
213239

214240
A common optimisation to the loading strategy is to preload the image before swapping it for the placeholder.

0 commit comments

Comments
 (0)