smooth-loader 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/lib/js/LazyLoader.d.ts.map +1 -1
- package/lib/js/LazyLoader.js +4 -2
- package/lib/js/LazyLoader.js.map +1 -1
- package/package.json +3 -2
- package/src/LazyLoader.ts +7 -3
package/README.md
CHANGED
|
@@ -23,11 +23,10 @@ npm i smooth-loader
|
|
|
23
23
|
yarn add smooth-loader
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Import `smooth-loader` and the core CSS. This assumes you're using a module bundler like webpack.
|
|
27
|
-
|
|
28
26
|
```js
|
|
29
27
|
import smoothLoader from 'smooth-loader'
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
smoothLoader()
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
# Usage
|
|
@@ -36,8 +35,7 @@ To make image or element Lazy loaded, replace `src` attribute with `data-src`
|
|
|
36
35
|
on image element, and add `data-src` attribute to elements that have background
|
|
37
36
|
image that you want to lazy load.
|
|
38
37
|
|
|
39
|
-
- Add **smooth-loader** css class to each image or element that you want
|
|
40
|
-
Unless you want to specify your own selector for images instead of **smooth-loader**.
|
|
38
|
+
- Add **smooth-loader** css class to each image or element that you want or specify your own selector for images instead of **smooth-loader**.
|
|
41
39
|
- Call `smoothLoader()` function when you want to lazy load images.
|
|
42
40
|
|
|
43
41
|
```js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LazyLoader.d.ts","sourceRoot":"","sources":["../../src/LazyLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,eAAe,CAGtB;gBAEkB,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;IAIhD;;;OAGG;IACH,OAAO,CAAC,SAAS;
|
|
1
|
+
{"version":3,"file":"LazyLoader.d.ts","sourceRoot":"","sources":["../../src/LazyLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,eAAe,CAGtB;gBAEkB,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;IAIhD;;;OAGG;IACH,OAAO,CAAC,SAAS;IAkBjB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;;;OAIG;IACI,OAAO,IAAI,IAAI;CAKzB"}
|
package/lib/js/LazyLoader.js
CHANGED
|
@@ -18,15 +18,17 @@ class default_1 {
|
|
|
18
18
|
*/
|
|
19
19
|
loadImage(img) {
|
|
20
20
|
const imageUrl = img.getAttribute('data-src');
|
|
21
|
+
img.style.opacity = '0';
|
|
22
|
+
img.style.transition = 'opacity 777ms';
|
|
21
23
|
if (!imageUrl)
|
|
22
24
|
return;
|
|
23
25
|
if (img.tagName === 'IMG') {
|
|
24
26
|
img.setAttribute('src', imageUrl);
|
|
25
|
-
img.addEventListener('load', () => img.
|
|
27
|
+
img.addEventListener('load', () => img.style.opacity = '1');
|
|
26
28
|
}
|
|
27
29
|
else {
|
|
28
30
|
img.style.backgroundImage = `url(${img.getAttribute('data-src')})`;
|
|
29
|
-
setTimeout(() => img.
|
|
31
|
+
setTimeout(() => img.style.opacity = '1', 0);
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
/**
|
package/lib/js/LazyLoader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LazyLoader.js","sourceRoot":"","sources":["../../src/LazyLoader.ts"],"names":[],"mappings":";;AAEA;;;GAGG;AACH;IAOI,YAAmB,MAA6B;QALxC,oBAAe,GAAG;YACtB,IAAI,EAAE,IAAI;YACV,SAAS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AAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YAC5D,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACpB,IAAI,KAAK,CAAC,cAAc,EAAE;oBACtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;oBACnB,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;iBAC1B;YACL,CAAC,CAAC,CAAA;QACN,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QAExB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QACpF,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AA3DD,4BA2DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smooth-loader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "This package allows you to lazy load your images using IntersectionObserver technology. It supports loading background images as well as the regular images with img tag.",
|
|
5
5
|
"main": "lib/js/index.js",
|
|
6
6
|
"types": "lib/js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc -p .",
|
|
12
|
-
"watch": "tsc --watch"
|
|
12
|
+
"watch": "tsc --watch",
|
|
13
|
+
"publish": "npm publish"
|
|
13
14
|
},
|
|
14
15
|
"keywords": ["lazy loader", "lazy", "image loader", "lazy loading", "background image"],
|
|
15
16
|
"author": "Serhii Cho",
|
package/src/LazyLoader.ts
CHANGED
|
@@ -22,14 +22,18 @@ export default class {
|
|
|
22
22
|
private loadImage(img: LazyImage): void {
|
|
23
23
|
const imageUrl = img.getAttribute('data-src')
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
img.style.opacity = '0'
|
|
26
|
+
img.style.transition = 'opacity 777ms'
|
|
27
|
+
|
|
28
|
+
if (!imageUrl)
|
|
29
|
+
return
|
|
26
30
|
|
|
27
31
|
if (img.tagName === 'IMG') {
|
|
28
32
|
img.setAttribute('src', imageUrl)
|
|
29
|
-
img.addEventListener('load', () => img.
|
|
33
|
+
img.addEventListener('load', () => img.style.opacity = '1')
|
|
30
34
|
} else {
|
|
31
35
|
img.style.backgroundImage = `url(${img.getAttribute('data-src')})`
|
|
32
|
-
setTimeout(() => img.
|
|
36
|
+
setTimeout(() => img.style.opacity = '1', 0)
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|