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
React Lazy Load is an easy-to-use React component which helps you defer loading content in predictable way. It's fast, works in IE8+, 6KB minified and uses debounce function by default. You can also use component inside scrolling container, such as div with scrollbar. It will be found automatically. Check out an example.
4
+
React Lazy Load is an easy-to-use React component which helps you defer loading content in predictable way. It's fast, You can also use component inside scrolling container, such as div with scrollbar. It will be found automatically. Check out an example.
Converted to work with React 18, and updated to use the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
11
+
12
+
### Breaking changes
13
+
* No more debunce, or throttle options as they aren't needed
14
+
* Removed individual offset props, offset can be used just like css margin, eg. `offset={'0px 10px 200px 0px'}` or `offset={100}`
15
+
16
+
### Improvements
17
+
Since we're now using the intersection observer we don't need to watch a user scroll, more importantly we don't have to manually calculate if a user can see the element or not.
18
+
Also took this oppourtunity to convert over to TS.
The `offset` option allows you to specify how far below, above, to the left, and to the right of the viewport you want to _begin_ displaying your content. If you specify `0`, your content will be displayed as soon as it is visible in the viewport, if you want to load _1000px_ below or above the viewport, use `1000`.
61
-
62
-
#### offsetVertical
63
-
Type: `Number|String` Default: `offset`'s value
64
-
65
-
The `offsetVertical` option allows you to specify how far above and below the viewport you want to _begin_ displaying your content.
66
-
67
-
#### offsetHorizontal
68
-
Type: `Number|String` Default: `offset`'s value
69
-
70
-
The `offsetHorizontal` option allows you to specify how far to the left and right of the viewport you want to _begin_ displaying your contet.
46
+
### Loading the image 300px prior to scroll
71
47
72
-
#### offsetTop
73
-
Type: `Number|String` Default: `offsetVertical`'s value
74
-
75
-
The `offsetTop` option allows you to specify how far above the viewport you want to _begin_ displaying your content.
Type: `Number|String` Default: `offsetVertical`'s value
89
82
90
-
The `offsetRight` option allows you to specify how far to the right of the viewport you want to _begin_ displaying your content.
83
+
## Props
91
84
92
-
#### throttle
93
-
Type: `Number|String` Default: `250`
85
+
#### offset
86
+
Type: `Number|String` Default: `0`
94
87
95
-
The throttle is managed by an internal function that prevents performance issues from continuous firing of `scroll` events. Using a throttle will set a small timeout when the user scrolls and will keep throttling until the user stops. The default is `250` milliseconds.
88
+
The `offset` option allows you to specify how far below, above, to the left, and to the right of the viewport you want to _begin_ displaying your content. If you specify `0`, your content will be displayed as soon as it is visible in the viewport, if you want to load _1000px_ below or above the viewport, use `1000`.
96
89
97
-
#### debounce
98
-
Type: `Boolean` Default: `true`
90
+
#### threshold
91
+
Type: `Number` Default: `0`
99
92
100
-
By default the throttling function is actually a [debounce](https://lodash.com/docs#debounce) function so that the checking function is only triggered after a user stops scrolling. To use traditional throttling where it will only check the loadable content every `throttle` milliseconds, set `debounce` to `false`.
93
+
This `threshold` option allows you to specify how much of the element must be shown on the screen prior to loading. This requires a _width_ and _height_ to be set on the `<LazyLoad>` component in order for the browser to calcualte the viewable area.
101
94
102
95
#### height
103
96
Type: `String|Number`
@@ -113,3 +106,20 @@ The `width` option allows you to set the element's width even when it has no con
113
106
Type `Function`
114
107
115
108
A callback function to execute when the content appears on the screen.
0 commit comments