smooth-loader 1.1.1 → 1.1.3

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -133
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ----
4
4
 
5
+ ## v1.1.3 (2023-11-19)
6
+
7
+ - Changed readme.md file
8
+
9
+ ----
10
+
11
+ ## v1.1.2 (2022-12-04)
12
+
13
+ - Removed line from docs;
14
+
15
+ ----
16
+
5
17
  ## v1.1.1 (2022-12-04)
6
18
 
7
19
  - Code refactoring;
package/README.md CHANGED
@@ -1,138 +1,7 @@
1
- - Documentation menu
2
- - [📄 Description](#-description)
3
- - [🎁 Features](#-features)
4
- - [✍️ Usage](#%EF%B8%8F-usage)
5
- - [🌄 Image preview](#-image-preview)
6
- - [⚙️ Configurations](#%EF%B8%8F-configurations)
7
- - [🚀️ Quick start](#-quick-start)
8
- - Useful links
9
- - [NPM](https://www.npmjs.com/package/smooth-loader)
10
- - [Usage on codesandbox](https://codesandbox.io/s/smooth-loader-example-usage-5xr6h)
11
- - [Example usage in production](https://shobar.com.ua/category/photo-reports)
12
-
13
- ## 📄 Description
1
+ ![Smooth loader logo](https://smooth-loader.github.io/images/logo.png)
14
2
 
15
3
  Smooth loader allows you smoothly lazy load images and background images. Lazy Loading defers the loading of an image that is not needed on the page immediately. An image, not visible to the user when the page loads, is loaded later when the user scrolls and the image actually becomes visible. If the user never scrolls, an image that is not visible to the user never gets loaded.
16
4
 
17
5
  This package is a MUST-HAVE for every website containing multiple images on the page. It's surely the best lazy loading package on NPM that you can configure to your own needs.
18
6
 
19
- ## 🎁 Features
20
-
21
- - 😍 Well-documented;
22
- - 😍 Written in TypeScript;
23
- - 😍 Very small package;
24
- - 😍 Loads images with IMG tag and backgrounds;
25
- - 😍 Loads images with a smooth fade in animation;
26
- - 😍 For image elements, you can show minified version of the image on initial page load;
27
- - 😍 Configurable;
28
- - 😍 Smooth loader for Vue 3 is coming soon;
29
-
30
- ## ✍️ Usage
31
-
32
- To make image element or background image lazy loaded:
33
- - Add image URL to `data-src` attribute;
34
- - Call `smoothLoader()` function;
35
-
36
- #### Look at several options to choose images which you want to lazy load:
37
-
38
- ```js
39
- import smoothLoader from 'smooth-loader'
40
-
41
- // Default selector
42
- // Selects all images with 'smooth-loader' class
43
- smoothLoader()
44
-
45
- // Custom selector
46
- // Selects all images with 'lazy-image' class
47
- smoothLoader('.lazy-image')
48
-
49
- // Elements
50
- // Selects all the images
51
- const images = document.querySelectorAll<HTMLImageElement>('img')
52
- smoothLoader(images)
53
-
54
- // Certain elements
55
- // Selects all the images
56
- const myPhoto = document.querySelector<HTMLImageElement>('#me')
57
-
58
- if (myPhoto) {
59
- smoothLoader([myPhoto])
60
- }
61
- ```
62
-
63
- > Note, that lazy loading works only when your elements are already in the DOM. Meaning, if images are loaded after the `smoothLoader` was executed, lazy loading will not work.
64
-
65
- ```html
66
- <!-- Regular image -->
67
- <img
68
- src="./images/me-min.webp"
69
- data-src="./images/me.webp"
70
- class="smooth-loader"
71
- alt="Photo of Serhii Cho"
72
- />
73
-
74
- <!-- Background image -->
75
- <div
76
- data-src="./images/we.png"
77
- class="smooth-loader my-bg-image"
78
- ></div>
79
- ```
80
-
81
- ## 🌄 Image preview
82
-
83
- You can add a small version of the image to `src` attribute on image element `<img src="here">`, so that users don't look at the empty place when image is loading. It can be useful if you have many images on the page or you have several large images which.
84
-
85
- To use this feature, you'll need small versions of your images which will be loaded right away when the page loads. Let's say I have 2 same images with different sizes:
86
-
87
- ![Big and small images](https://serhii.io/storage/other/big-and-small-images.png)
88
-
89
- I want to load a small image on the initial page load, and when person scrolls into the image view, the bigger version will be loaded and it will replace the small one. In my HTML I will simply add an `src` attribute with path to a small image.
90
-
91
- ```html
92
- <img
93
- alt="Beautiful girl"
94
- class="smooth-loader"
95
- src="images/1min.jpg"
96
- data-src="images/1.jpg"
97
- width="736"
98
- height="725"
99
- />
100
- ```
101
-
102
- > It's important to add `width` and `height` attributes or have width and hight setup correctly with CSS. Because small image has to be filling all the space that large image is taking.
103
-
104
- > This feature works only for image elements, background images do not support it yet!
105
-
106
- Instead of the small version of your image you can use just a small placeholder image, and it will work fine.
107
-
108
- ## ⚙️ Configurations
109
-
110
- As the second argument, you can pass configurations. Some of the parameters extend [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
111
-
112
- ```typescript
113
- smoothLoader('.lazy-image', {
114
- root: document.querySelector('#scrollArea'),
115
- rootMargin: '0px',
116
- threshold: 1.0,
117
- })
118
- ```
119
-
120
- - `root`: The element that is used as the viewport for checking visibility of the target. Must be the ancestor of the target. Defaults to the browser viewport if not specified or if null.
121
- - `rootMargin`: Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). The values can be percentages. This set of values serves to grow or shrink each side of the root element's bounding box before computing intersections. Defaults to all zeros.
122
- - `threshold`: Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed. If you only want to detect when visibility passes the 50% mark, you can use a value of 0.5. If you want the callback to run every time visibility passes another 25%, you would specify the array [0, 0.25, 0.5, 0.75, 1]. The default is 0 (meaning as soon as even one pixel is visible, the callback will be run). A value of 1.0 means that the threshold isn't considered passed until every pixel is visible.
123
-
124
- ## 🚀 Quick Start
125
-
126
- ```bash
127
- # npm
128
- npm i smooth-loader
129
-
130
- # yarn
131
- yarn add smooth-loader
132
- ```
133
-
134
- ```js
135
- import smoothLoader from 'smooth-loader'
136
-
137
- smoothLoader()
138
- ```
7
+ ## Follow the [official documentation](https://smooth-loader.github.io) for all the details
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smooth-loader",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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",
@@ -21,5 +21,5 @@
21
21
  ],
22
22
  "author": "Serhii Cho",
23
23
  "license": "MIT",
24
- "homepage": "https://github.com/SerhiiCho/smooth-loader#readme"
24
+ "homepage": "https://smooth-loader.github.io"
25
25
  }