File tree Expand file tree Collapse file tree 1 file changed +23
-18
lines changed Expand file tree Collapse file tree 1 file changed +23
-18
lines changed Original file line number Diff line number Diff line change @@ -59,28 +59,33 @@ loadImages($('img', '.main-content'))
59
59
60
60
```
61
61
62
- #### Load sequentially images using a generator
62
+ #### Lazy load sequentially images using a generator
63
63
64
64
``` js
65
65
import { loadImagesGen } from ' bianco.images-loader'
66
66
67
- const loader = loadImagesGen ([
68
- ' path/to/the/image1.jpg' ,
69
- ' path/to/the/image2.jpg' ,
70
- ' path/to/the/image3.jpg'
71
- ])
72
-
73
- // load the first image
74
- loader .next ().value .then (img => {
75
- // do something with the image
76
-
77
- // do something with the remaining images to load
78
- for (let promise of loader) {
79
- promise .then (i => {
80
- // do whathever you want here
81
- })
82
- }
83
- })
67
+ const infiniteList = loadImagesGen ([... many images])
68
+
69
+ // load the first 10 images
70
+ let i = 10
71
+ while (i-- ) {
72
+ infiniteList .next ().value .then (onImageLoaded)
73
+ }
74
+
75
+ // do something
76
+
77
+ // load other 5 images
78
+ i = 5
79
+ while (i-- ) {
80
+ infiniteList .next ().value .then (onImageLoaded)
81
+ }
82
+
83
+ // do something else
84
+
85
+ // load the remaining images
86
+ for (let promise of infiniteList) {
87
+ promise .next ().value .then (onImageLoaded)
88
+ }
84
89
```
85
90
86
91
## API
You can’t perform that action at this time.
0 commit comments