7
7
[ ![ CodeFactor Grade] ( https://img.shields.io/codefactor/grade/github/shinsenter/defer.js )] ( https://www.codefactor.io/repository/github/shinsenter/defer.js )
8
8
9
9
* * *
10
+
10
11
[ ![ GitHub Release Date] ( https://img.shields.io/github/release-date/shinsenter/defer.js )] ( https://github.com/shinsenter/defer.js/releases )
11
12
[ ![ GitHub package.json version] ( https://img.shields.io/github/package-json/v/shinsenter/defer.js )] ( https://github.com/shinsenter/defer.js/releases )
12
13
[ ![ npm bundle size (scoped)] ( https://img.shields.io/bundlephobia/minzip/@shinsenter/defer.js )] ( https://www.npmjs.com/package/@shinsenter/defer.js )
20
21
- ** Copyright** : 2021 AppSeeds < https://code.shin.company/ >
21
22
- ** License** : [ MIT] ( https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE )
22
23
23
-
24
24
* * *
25
25
26
26
@@ -46,13 +46,13 @@ Furthermore [defer.js](#Defer) also gives you very simple ways
46
46
to flexibly optimize other resources in your website.
47
47
48
48
49
- ## Key features
49
+ ## Good points
50
50
51
51
- 🧶 Under 1KB (gzipped)
52
52
- 🎯 No dependencies, no jQuery
53
53
- ⚡️ Native API, blazing fast
54
- - ✅ Legacy browsers support (IE9+)
55
- - 🧩 Lazy load almost everything
54
+ - ✅ Supports legacy browsers (IE9+)
55
+ - 🧩 Lazy loading for almost everything
56
56
- 👍 Very easy to use
57
57
- 🤝 Works well with your favorite frameworks
58
58
@@ -61,7 +61,7 @@ to flexibly optimize other resources in your website.
61
61
62
62
Available in latest browsers,
63
63
also works perfectly with Internet Explorer 9
64
- <sup title = " With including `IntersectionObserver` polyfill library" > * </sup > and later.
64
+ <sup > * (with ` IntersectionObserver ` polyfill library) </sup< > and later.
65
65
66
66
- 🖥 IE9+ / Microsoft EDGE *
67
67
- 🖥 Firefox 4+
@@ -85,14 +85,13 @@ just below the opening `<head>` tag:
85
85
<title >My Awesome Page</title >
86
86
87
87
<!-- Put defer.min.js here -->
88
- <script src =" defer.js/dist/defer.min.js" ></script >
89
- <!-- From CDN: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js/dist/defer.min.js -->
88
+ <script src =" defer.js@2.0.0 /dist/defer.min.js" ></script >
89
+ <!-- From CDN: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.0.0 /dist/defer.min.js -->
90
90
91
91
<!-- ... -->
92
92
</head >
93
93
```
94
94
95
-
96
95
### Compatibility with previous releases
97
96
98
97
I strongly recommend that you should migrate
@@ -104,8 +103,8 @@ instead of `defer.min.js`.
104
103
105
104
``` html
106
105
<!-- Put defer_plus.min.js here -->
107
- <script src =" defer.js/dist/defer_plus.min.js" ></script >
108
- <!-- From CDN: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js/dist/defer_plus.min.js -->
106
+ <script src =" defer.js@2.0.0 /dist/defer_plus.min.js" ></script >
107
+ <!-- From CDN: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.0.0 /dist/defer_plus.min.js -->
109
108
```
110
109
111
110
### Inlining the library
@@ -140,9 +139,9 @@ to minimize the number of requests.
140
139
141
140
## Typedefs
142
141
143
- * [ Node] ( #Node )
144
142
* [ function] ( #function ) ⇒ <code >void</code >
145
143
* [ closure] ( #closure ) ⇒ <code >void</code > \| <code >bool</code >
144
+ * [ Node] ( #Node )
146
145
147
146
<a name =" Defer " ></a >
148
147
@@ -394,9 +393,9 @@ Then it will add a CSS class `loaded` to the fully lazy loaded image element.
394
393
395
394
<!-- Here may be a very long content -->
396
395
397
- <img class =" lazy-extra" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=1 " width =" 200" height =" 300" />
398
- <img class =" lazy-extra" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=2 " width =" 200" height =" 300" />
399
- <img class =" lazy-extra" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=3 " width =" 200" height =" 300" />
396
+ <img class =" lazy-extra" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=4 " width =" 200" height =" 300" />
397
+ <img class =" lazy-extra" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=5 " width =" 200" height =" 300" />
398
+ <img class =" lazy-extra" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=6 " width =" 200" height =" 300" />
400
399
```
401
400
** Example**
402
401
Advanced usage: Lazy load with [ Intersection observer options] ( https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Intersection_observer_options )
@@ -411,9 +410,9 @@ Advanced usage: Lazy load with [Intersection observer options](https://developer
411
410
412
411
<!-- Here may be a very long content -->
413
412
414
- <img class =" lazy-sooner" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=1 " width =" 200" height =" 300" />
415
- <img class =" lazy-sooner" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=2 " width =" 200" height =" 300" />
416
- <img class =" lazy-sooner" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=3 " width =" 200" height =" 300" />
413
+ <img class =" lazy-sooner" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=7 " width =" 200" height =" 300" />
414
+ <img class =" lazy-sooner" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=8 " width =" 200" height =" 300" />
415
+ <img class =" lazy-sooner" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=9 " width =" 200" height =" 300" />
417
416
```
418
417
** Example**
419
418
We can use CSS class that added to the lazy loaded element
@@ -434,9 +433,9 @@ to add animation to the successfully loaded elements.
434
433
435
434
<!-- Here may be a very long content -->
436
435
437
- <img class =" fade" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=1 " width =" 200" height =" 300" />
438
- <img class =" fade" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=2 " width =" 200" height =" 300" />
439
- <img class =" fade" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=3 " width =" 200" height =" 300" />
436
+ <img class =" fade" alt =" Photo 1" data-src =" https://picsum.photos/200/300?random=10 " width =" 200" height =" 300" />
437
+ <img class =" fade" alt =" Photo 2" data-src =" https://picsum.photos/200/300?random=11 " width =" 200" height =" 300" />
438
+ <img class =" fade" alt =" Photo 3" data-src =" https://picsum.photos/200/300?random=12 " width =" 200" height =" 300" />
440
439
```
441
440
** Example**
442
441
This function can be used similarly for other tags
@@ -476,19 +475,19 @@ such as `<iframe>`, `<video>`, `<audio>`, `<picture>` tags.
476
475
```
477
476
** Example**
478
477
Or even execute a piece of JavaScript
479
- when the user scrolls to the element ` #my_div ` .
478
+ when the user scrolls to the element ` #scroll_reveal ` .
480
479
481
480
``` html
482
481
<script >
483
- // Show an alert when user scrolled to #my_div
484
- Defer .dom (' #my_div ' , null , null , function (element ) {
482
+ // Show an alert when user scrolled to #scroll_reveal
483
+ Defer .dom (' #scroll_reveal ' , null , null , function (element ) {
485
484
window .alert (' You scrolled to #' + element .id );
486
485
});
487
486
</script >
488
487
489
488
<!-- Here may be a very long content -->
490
489
491
- <div id =" my_div " >
490
+ <div id =" scroll_reveal " >
492
491
This is my content.
493
492
</div >
494
493
```
@@ -586,16 +585,6 @@ Defer.js(base + '/highlight.pack.min.js', 'hljs-js', 1000, function () {
586
585
| [ observeOptions] | <code >object</code > |
587
586
588
587
589
- * * *
590
-
591
- <a name =" Node " ></a >
592
-
593
- ## Node
594
- The DOM Node interface
595
-
596
- ** Kind** : global typedef
597
- ** See** : [ https://developer.mozilla.org/en-US/docs/Web/API/Node ] ( https://developer.mozilla.org/en-US/docs/Web/API/Node )
598
-
599
588
* * *
600
589
601
590
<a name =" function " ></a >
@@ -620,6 +609,16 @@ The definition for a function that takes one parameter is a DOM [Node](#Node) el
620
609
| element | [ <code >Node</code >] ( #Node ) | The DOM [ Node] ( #Node ) element |
621
610
622
611
612
+ * * *
613
+
614
+ <a name =" Node " ></a >
615
+
616
+ ## Node
617
+ The DOM Node interface
618
+
619
+ ** Kind** : global typedef
620
+ ** See** : [ https://developer.mozilla.org/en-US/docs/Web/API/Node ] ( https://developer.mozilla.org/en-US/docs/Web/API/Node )
621
+
623
622
* * *
624
623
625
624
## Defer.js for another platforms
0 commit comments