Skip to content

Commit 1adb8d9

Browse files
committed
Merge pull request #41 from loktar00/v3
Huge 3.0.0 release
2 parents c13a25c + 00bc890 commit 1adb8d9

File tree

7 files changed

+275
-104
lines changed

7 files changed

+275
-104
lines changed

README.md

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
React Lazy Load Component
22
=========================
33

4-
Really simple component that renders children elements when they enter the viewport.
4+
React Lazy Load is 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.
55

66
[![build status](https://img.shields.io/travis/loktar00/react-lazy-load.svg?style=flat-square)](https://travis-ci.org/loktar00/react-lazy-load)
77
[![dependency status](https://david-dm.org/loktar00/react-lazy-load.svg?style=flat-square)](https://david-dm.org/loktar00/react-lazy-load)
@@ -20,48 +20,91 @@ npm install --save react-lazy-load
2020
## Usage
2121

2222
```jsx
23-
import React, { Component } from 'react';
23+
import React from 'react';
2424
import LazyLoad from 'react-lazy-load';
2525

26-
class MyComponent extends Component {
27-
render() {
28-
return (
29-
<LazyLoad>
30-
<div>some content</div>
31-
</LazyLoad>
32-
);
33-
}
34-
}
26+
const MyComponent = () => (
27+
<div>
28+
Scroll to load images.
29+
<div className="filler" />
30+
<LazyLoad height={762} offsetVertical={300}>
31+
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' />
32+
</LazyLoad>
33+
<div className="filler" />
34+
<LazyLoad height={683} offsetTop={200}>
35+
<img src='http://apod.nasa.gov/apod/image/1502/2015_02_20_conj_bourque1024.jpg' />
36+
</LazyLoad>
37+
<div className="filler" />
38+
<LazyLoad height={480} offsetHorizontal={50}>
39+
<img src='http://apod.nasa.gov/apod/image/1502/MarsPlume_jaeschke_480.gif' />
40+
</LazyLoad>
41+
<div className="filler" />
42+
<LazyLoad
43+
height={720}
44+
onContentVisible={() => console.log('look ma I have been lazyloaded!')}
45+
>
46+
<img src='http://apod.nasa.gov/apod/image/1502/ToadSky_Lane_1080_annotated.jpg' />
47+
</LazyLoad>
48+
<div className="filler" />
49+
</div>
50+
);
3551
```
3652

3753
## Props
3854

39-
### height={String|Number}
55+
#### offset
56+
Type: `Number|String` Default: `0`
4057

41-
This is used to set the elements height even when it contains no content.
58+
Aliases: `threshold`
4259

43-
```jsx
44-
<LazyLoad height={100}>
45-
<div>some content</div>
46-
</LazyLoad>
47-
```
60+
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`.
4861

49-
### threshold={Number}
62+
#### offsetVertical
63+
Type: `Number|String` Default: `offset`'s value
5064

51-
By default content is loaded when it appears on the screen. If you want content to load earlier use threshold parameter. Setting threshold to 200 causes image to load 200 pixels before it appears on viewport.
65+
The `offsetVertical` option allows you to specify how far above and below the viewport you want to _begin_ displaying your content.
5266

53-
```jsx
54-
<LazyLoad threshold={200}>
55-
<div>some content</div>
56-
</LazyLoad>
57-
```
67+
#### offsetHorizontal
68+
Type: `Number|String` Default: `offset`'s value
5869

59-
### onContentVisible={Function}
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.
6071

61-
A callback function to execute when the content appears on the screen.
72+
#### offsetTop
73+
Type: `Number|String` Default: `offsetVertical`'s value
6274

63-
```jsx
64-
<LazyLoad onContentVisible={() => { console.log('content visible'); }}>
65-
<div>some content</div>
66-
</LazyLoad>
67-
```
75+
The `offsetTop` option allows you to specify how far above the viewport you want to _begin_ displaying your content.
76+
77+
#### offsetBottom
78+
Type: `Number|String` Default: `offsetVertical`'s value
79+
80+
The `offsetBottom` option allows you to specify how far below the viewport you want to _begin_ displaying your content.
81+
82+
#### offsetLeft
83+
Type: `Number|String` Default: `offsetVertical`'s value
84+
85+
The `offsetLeft` option allows you to specify how far to left of the viewport you want to _begin_ displaying your content.
86+
87+
#### offsetRight
88+
Type: `Number|String` Default: `offsetVertical`'s value
89+
90+
The `offsetRight` option allows you to specify how far to the right of the viewport you want to _begin_ displaying your content.
91+
92+
#### throttle
93+
Type: `Number|String` Default: `250`
94+
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.
96+
97+
#### debounce
98+
Type: `Boolean` Default: `true`
99+
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`.
101+
102+
### height
103+
Type: `String|Number` Default: `100`
104+
105+
This is used to set the elements height even when it has no content.
106+
107+
### onContentVisible
108+
Type `Function`
109+
110+
A callback function to execute when the content appears on the screen.

examples/basic/src/components/Application/index.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ class Application extends Component {
99
<div>
1010
Scroll to load images.
1111
<div className="filler" />
12-
<LazyLoad height={762} threshold={100}>
12+
<LazyLoad height={762} offsetVertical={300}>
1313
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' />
1414
</LazyLoad>
1515
<div className="filler" />
16-
<LazyLoad height={683}>
16+
<LazyLoad height={683} offsetVertical={300}>
1717
<img src='http://apod.nasa.gov/apod/image/1502/2015_02_20_conj_bourque1024.jpg' />
1818
</LazyLoad>
1919
<div className="filler" />
20-
<LazyLoad height={480}>
21-
<img src='http://apod.nasa.gov/apod/image/1502/MarsPlume_jaeschke_480.gif' />
22-
</LazyLoad>
20+
<div className="ScrollableContainer">
21+
<div className="filler" />
22+
<div className="filler" />
23+
<div className="filler" />
24+
<LazyLoad height={480}>
25+
<img src='http://apod.nasa.gov/apod/image/1502/MarsPlume_jaeschke_480.gif' />
26+
</LazyLoad>
27+
</div>
2328
<div className="filler" />
24-
<LazyLoad height={720}>
29+
<LazyLoad height={720} offsetVertical={300}>
2530
<img src='http://apod.nasa.gov/apod/image/1502/ToadSky_Lane_1080_annotated.jpg' />
2631
</LazyLoad>
2732
<div className="filler" />
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
.filler {
2-
height: 300px;
3-
}
4-
5-
.lazy-load {
1+
.LazyLoad {
62
opacity: 0;
73
transition: all 2s ease-in-out;
4+
5+
&.is-visible {
6+
opacity: 1;
7+
}
8+
}
9+
10+
.filler {
11+
height: 150px;
812
}
913

10-
.lazy-load-visible {
11-
opacity: 1;
14+
.ScrollableContainer {
15+
height: 200px;
16+
overflow: scroll;
17+
background-color: grey;
1218
}

package.json

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
22
"name": "react-lazy-load",
3-
4-
"version": "2.0.2",
5-
3+
"version": "3.0.0",
64
"description": "Simple lazy loading component built with react",
7-
85
"main": "./lib/LazyLoad.js",
9-
106
"scripts": {
117
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
128
"build:lib": "babel src --out-dir lib",
@@ -17,33 +13,26 @@
1713
"prepublish": "npm run clean && npm run build",
1814
"test": "echo \"Error: no test specified\" && exit 1"
1915
},
20-
2116
"repository": {
2217
"type": "git",
2318
"url": "https://github.com/loktar00/react-lazy-load.git"
2419
},
25-
2620
"files": [
2721
"dist",
2822
"lib"
2923
],
30-
3124
"keywords": [
3225
"react",
3326
"reactjs",
3427
"react-component",
3528
"load",
3629
"lazy"
3730
],
38-
3931
"author": "Jason Brown <[email protected]> (https://twitter.com/loktar00)",
40-
4132
"contributors": [
4233
"Sergey Laptev <[email protected]> (https://twitter.com/iamsergeylaptev)"
4334
],
44-
4535
"license": "MIT",
46-
4736
"devDependencies": {
4837
"babel-cli": "^6.3.17",
4938
"babel-core": "^6.2.1",
@@ -60,13 +49,12 @@
6049
"rimraf": "^2.4.4",
6150
"webpack": "^1.12.2"
6251
},
63-
6452
"dependencies": {
65-
"classnames": "^2.2.0"
53+
"eventlistener": "0.0.1",
54+
"lodash.debounce": "^4.0.0"
6655
},
67-
6856
"peerDependencies": {
6957
"react": "^0.14.0",
7058
"react-dom": "^0.14.0"
7159
}
72-
}
60+
}

0 commit comments

Comments
 (0)