chameleon-backgrounds 2.1.2 → 3.0.0

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  A **zero-dependency** JavaScript library to dynamically load background images with elegant fade-in transitions and slideshow support.
4
4
 
5
+ > **v3.0** — Added responsive `srcset`, seamless crossfading, lazy-loading, and play/pause API.
5
6
  > **v2.0** — Fully rewritten from scratch. No jQuery required.
6
7
 
7
8
  ---
@@ -13,9 +14,13 @@ Large background images slow down initial page loads. ChameleonBackgrounds **def
13
14
  ## Features
14
15
 
15
16
  - 🎯 **Zero dependencies** — no jQuery, no frameworks
16
- - 🖼️ **Single image** mode with preload + fade-in
17
+ - 🖼️ **Responsive images** native `srcset` and `sizes` support
17
18
  - 🎠 **Slider** mode with configurable duration and looping
19
+ - ✨ **Crossfade & Solid** transitions
20
+ - ⚡ **Lazy loading** via IntersectionObserver
21
+ - ♿ **Accessibility** — respects `prefers-reduced-motion`
18
22
  - 🎨 **Overlay** support with color, pattern images, and minimum opacity
23
+ - 🎛️ **Play / Pause API** for manual control
19
24
  - 🧹 **`destroy()`** method for clean teardown
20
25
  - 📦 **ES Module** + **UMD** dual distribution
21
26
  - 🔄 **Backward compatible** with v1 snake_case option names
@@ -112,21 +117,50 @@ const bg = new ChameleonBackgrounds({
112
117
  bg.destroy();
113
118
  ```
114
119
 
120
+ ### Responsive Images
121
+
122
+ You can provide an object containing `url`, `srcset`, and `sizes` properties to leverage native browser responsive image support. This works perfectly for both `type: 'single'` and `type: 'slider'`.
123
+
124
+ ```js
125
+ // Example using responsive images in a slider
126
+ const bg = new ChameleonBackgrounds({
127
+ element: '#hero',
128
+ type: 'slider',
129
+ src: [
130
+ {
131
+ url: './img/slide1.jpg',
132
+ srcset: './img/slide1-mobile.jpg 480w, ./img/slide1.jpg 1920w',
133
+ sizes: '100vw'
134
+ },
135
+ {
136
+ url: './img/slide2.jpg',
137
+ srcset: './img/slide2-mobile.jpg 480w, ./img/slide2.jpg 1920w',
138
+ sizes: '100vw'
139
+ }
140
+ ],
141
+ transitionDuration: 1500
142
+ });
143
+ ```
144
+
115
145
  ---
116
146
 
117
147
  ## Options
118
148
 
119
149
  | Option | Type | Default | Required | Description |
120
150
  |---|---|---|---|---|
121
- | `element` | `string \| HTMLElement` | `'body'` | yes | CSS selector or DOM element to attach to |
122
- | `type` | `'single' \| 'slider'` | `'single'` | yes | Background mode |
123
- | `src` | `string \| string[]` | `''` | yes | Image URL (single) or array of URLs (slider) |
124
- | `overlayColor` | `string` | `'#0f1e25'` | yes | Overlay color (hex, rgb, rgba, hsl) |
125
- | `overlayImage` | `string \| null` | `null` | no | Overlay pattern image URL |
126
- | `minOverlay` | `number` | `0` | no | Minimum overlay opacity after fade (0–1) |
127
- | `transitionDuration` | `number` | `2000` | yes | Fade duration in milliseconds |
128
- | `sliderDuration` | `number` | `8000` | slider only | Time each slide is shown (ms) |
129
- | `sliderLoop` | `boolean` | `false` | slider only | Restart slider after last slide |
151
+ | element | `string \| HTMLElement` | `'body'` | yes | CSS selector or DOM element to attach to |
152
+ | type | `'single' \| 'slider'` | `'single'` | yes | Background mode |
153
+ | src | `string \| array \| object` | `''` | yes | Image URL, array of URLs, or config object `{url, srcset, sizes}` |
154
+ | overlayColor | `string` | `'#0f1e25'` | yes | Overlay color (hex, rgb, rgba, hsl) |
155
+ | overlayImage | `string \| null` | `null` | no | Overlay pattern image URL |
156
+ | minOverlay | `number` | `0` | no | Minimum overlay opacity after fade (0–1) |
157
+ | transitionDuration | `number` | `2000` | yes | Fade duration in milliseconds |
158
+ | sliderDuration | `number` | `8000` | slider only | Time each slide is shown (ms) |
159
+ | sliderLoop | `boolean` | `false` | slider only | Restart slider after last slide |
160
+ | fetchPriority | `string` | `'auto'` | no | Network priority for the initial image load. |
161
+ | lazyLoad | `boolean` | `true` | no | Defer loading until element intersects viewport |
162
+ | transitionMode | `'solid' \| 'crossfade'` | `'solid'` | no | Transition effect. `'solid'` fades to overlay color, `'crossfade'` fades between images |
163
+ | respectReducedMotion | `boolean` | `false` | no | Auto-pause slider if user's OS has animations disabled |
130
164
 
131
165
  ### Legacy Option Names
132
166
 
@@ -140,6 +174,21 @@ For backward compatibility, v1 snake_case option names are still supported:
140
174
  | `min_overlay` | `minOverlay` |
141
175
  | `overlay_color` | `overlayColor` |
142
176
  | `overlay_image` | `overlayImage` |
177
+ | `lazy_load` | `lazyLoad` |
178
+ | `transition_mode` | `transitionMode` |
179
+ | `respect_reduced_motion` | `respectReducedMotion` |
180
+
181
+ ---
182
+
183
+ ## Optimize for Largest Contentful Paint (LCP)
184
+
185
+ To get a great LCP score on PageSpeed Insights, you should set `fetchPriority: 'high'` on your main above-the-fold background instance.
186
+
187
+ Additionally, because browsers cannot discover JavaScript-loaded images in the initial HTML document parse, you should add a preload link to your `<head>` for the hero image:
188
+
189
+ ```html
190
+ <link rel="preload" as="image" href="path/to/hero.jpg" fetchpriority="high">
191
+ ```
143
192
 
144
193
  ---
145
194
 
@@ -153,6 +202,14 @@ Creates a new instance and immediately begins loading.
153
202
 
154
203
  Stops any running slider, removes all injected DOM and styles, and restores the target element to its original state.
155
204
 
205
+ ### `.play()`
206
+
207
+ Resumes a paused slider.
208
+
209
+ ### `.pause()`
210
+
211
+ Pauses an active slider.
212
+
156
213
  ### `.getOptions()` / `.options` (ESM)
157
214
 
158
215
  Returns a read-only copy of the resolved options.