Skip to content

Commit 794f438

Browse files
authored
Merge pull request #3 from scaleflex/CI-489-adjust-config-js-carousel
Enhance carousel functionality with new thumbnail options and validation
2 parents 62cae81 + c47eb4b commit 794f438

File tree

11 files changed

+152
-13
lines changed

11 files changed

+152
-13
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<h1 align="center">
32
JS carousel | Cloudimage (DMO)
43
</h1>
@@ -12,11 +11,9 @@
1211
src="https://scaleflex.cloudimg.io/v7/plugins/js-carousel/carousel_exemple.png">
1312
</p>
1413

15-
16-
1714
### Introduction:
1815

19-
Meet `js-carousel` by Scaleflex—a minimal, no-nonsense JavaScript carousel plugin that does *exactly* what you need it to do: load fast, look slick, and play nice with performance. Designed with zero dependencies and a featherlight footprint, this carousel is tailor-made for developers and performance-obsessed teams who don’t want to trade speed for style. Whether you're running a headless CMS or optimizing for that last Lighthouse point, `js-carousel` by Scaleflex is the go-to solution.
16+
Meet `js-carousel` by Scaleflex—a minimal, no-nonsense JavaScript carousel plugin that does _exactly_ what you need it to do: load fast, look slick, and play nice with performance. Designed with zero dependencies and a featherlight footprint, this carousel is tailor-made for developers and performance-obsessed teams who don’t want to trade speed for style. Whether you're running a headless CMS or optimizing for that last Lighthouse point, `js-carousel` by Scaleflex is the go-to solution.
2017

2118
`js-carousel` by Scaleflex does not bundle in more features than you'll ever use, it focuses on doing one thing exceptionally well: delivering a fast, responsive, and ultra-smooth image slider & zoomer experience with minimal setup. It’s the smart choice for frontend engineers who value UX as much as DX. Simple to integrate, easy to customize, and built for scale.
2219

@@ -173,6 +170,32 @@ carousel.init()
173170
}
174171
```
175172

173+
### `thumbnailFitMode` (string)
174+
175+
- **Default**: `'crop-fit'`
176+
- **Options**: `'crop-fit'`, `'fit'`
177+
- **Description**: Controls how thumbnail images are fitted within their containers
178+
- **Example**:
179+
180+
```javascript
181+
{
182+
thumbnailFitMode: 'fit' // Makes thumbnails fit within their container without cropping
183+
}
184+
```
185+
186+
### `thumbnailAlignment` (string)
187+
188+
- **Default**: `'space-evenly'`
189+
- **Options**: `'left'`, `'center'`, `'right'`, `'space-evenly'`, `'space-between'`
190+
- **Description**: Controls the horizontal alignment of thumbnails in the thumbnail container
191+
- **Example**:
192+
193+
```javascript
194+
{
195+
thumbnailAlignment: 'space-between' // Distributes thumbnails with equal space between them
196+
}
197+
```
198+
176199
## Complete Example
177200

178201
Here's an example showing all options with their default values:
@@ -191,6 +214,8 @@ const carousel = new CloudImageCarousel('#my-carousel', {
191214
showControls: true,
192215
showBullets: false,
193216
transitionEffect: 'fade',
217+
thumbnailFitMode: 'crop-fit',
218+
thumbnailAlignment: 'space-evenly',
194219
images: ['path/to/image1.jpg', 'path/to/image2.jpg', 'path/to/image3.jpg'],
195220
})
196221

dist/js-carousel.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-carousel.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
autoplay: false,
1616
autoplayInterval: 3000,
1717
cycle: true,
18-
showFilenames: false,
18+
showFilenames: true,
1919
showThumbnails: true,
2020
showControls: true,
2121
showBullets: false,
2222
transitionEffect: 'slide',
23+
thumbnailFitMode: 'fit',
24+
thumbnailAlignment: 'center',
2325
images: [
2426
'https://demo.cloudimg.io/v7/https://samples.scaleflex.com/hotel.jpg',
2527
'https://demo.cloudimg.io/v7/https://samples.scaleflex.com/birds.jpg',
@@ -35,6 +37,7 @@
3537
'https://demo.cloudimg.io/v7/https://samples.scaleflex.com/Image02.jpg',
3638
'https://demo.cloudimg.io/v7/https://samples.scaleflex.com/Image04.jpg',
3739
'https://demo.cloudimg.io/v7/https://samples.scaleflex.com/plate1.jpg',
40+
'https://assets.scaleflex.com/Corporate+Branding/VXP+logo/VXP+logo+BLACK.png',
3841
],
3942
})
4043

src/css/carousel.css

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,28 @@
125125
.ci-carousel-thumbnail:hover {
126126
opacity: 0.9;
127127
transform: translateY(-2px);
128+
box-shadow: 0 0 0 2px #000000;
128129
}
129130

130131
.ci-carousel-thumbnail.active {
131132
opacity: 1;
132133
box-shadow: 0 0 0 2px #000000;
133134
transform: translateY(-2px);
135+
animation: fadeBoxShadow 5s ease-out forwards;
136+
}
137+
138+
@keyframes fadeBoxShadow {
139+
0% {
140+
box-shadow: 0 0 0 2px #000000;
141+
}
142+
100% {
143+
box-shadow: 0 0 0 0 transparent;
144+
}
134145
}
135146

136147
.ci-carousel-thumbnail img {
137148
width: 100%;
138149
height: 100%;
139-
object-fit: cover;
140150
}
141151

142152
/* Minimal Filename Display */
@@ -152,12 +162,13 @@
152162
font-size: 13px;
153163
font-weight: 500;
154164
letter-spacing: 0.3px;
155-
opacity: 0;
156165
transform: translateY(8px);
157-
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
166+
opacity: 0;
167+
transition: all 0.5s ease-in-out;
168+
box-sizing: border-box;
158169
}
159170

160-
.ci-carousel-image-wrapper:hover .ci-carousel-filename {
171+
.ci-carousel-has-filenames .ci-carousel-filename {
161172
opacity: 1;
162173
transform: translateY(0);
163174
}
@@ -207,3 +218,13 @@
207218
background: rgba(0, 0, 0, 0.5);
208219
backdrop-filter: blur(8px);
209220
}
221+
222+
.ci-carousel.is-fullscreen.ci-carousel-has-filenames .ci-carousel-filename {
223+
font-size: 20px;
224+
}
225+
226+
.ci-carousel.is-fullscreen.ci-carousel-has-filenames:hover .ci-carousel-filename {
227+
opacity: 1;
228+
font-size: 20px;
229+
bottom: 100px;
230+
}

src/css/controls.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
position: relative;
55
}
66

7+
.ci-carousel-has-filenames .ci-carousel-controls {
8+
top: -110px;
9+
}
10+
711
.ci-carousel-controls {
812
align-items: center;
913
display: flex;
1014
justify-content: space-between;
11-
width: 280px;
1215
z-index: 10;
13-
border-radius: 20px;
1416
width: 100%;
1517
padding: 30px;
1618
box-sizing: border-box;

src/js/carousel.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
} from './constants/classes.constants'
1616
import { CLICK_EVENT } from './constants/events.constants'
1717
import { ICONS } from './constants/icons.contants'
18+
import { THUMBNAIL_ALIGNMENT, THUMBNAIL_FIT_MODE } from './constants/thumbnails.contants'
1819
import { TRANSITION_EFFECTS } from './constants/transition.constants'
1920
import { CarouselControls } from './controls/controls'
2021
import { SwipeControls } from './controls/swipe.controls'
2122
import { ZoomPanControls } from './controls/zoom-pan.controls'
2223
import { getFilenameWithoutExtension } from './utils/image.utils'
24+
import { validateOptions } from './utils/validation.utils'
2325

2426
class CloudImageCarousel {
2527
/**
@@ -42,6 +44,9 @@ class CloudImageCarousel {
4244
)
4345
}
4446

47+
// Validate options before setting them
48+
validateOptions(options)
49+
4550
this.options = {
4651
images: options.images || [],
4752
autoplay: options.autoplay || false,
@@ -52,6 +57,8 @@ class CloudImageCarousel {
5257
showBullets: options.showBullets || false,
5358
showControls: options.showControls || true,
5459
transitionEffect: options.transitionEffect || TRANSITION_EFFECTS.FADE, // slide, fade
60+
thumbnailFitMode: options.thumbnailFitMode || THUMBNAIL_FIT_MODE.CROP_FIT, // fit, crop-fit
61+
thumbnailAlignment: options.thumbnailAlignment || THUMBNAIL_ALIGNMENT.SPACE_EVENLY, // left, center, right, space-evenly
5562
...options,
5663
}
5764

@@ -150,6 +157,11 @@ class CloudImageCarousel {
150157
this.bottomContainer.appendChild(this.bulletsContainer)
151158
}
152159

160+
// Bullets container
161+
if (this.options.showFilenames) {
162+
this.container.classList.add('ci-carousel-has-filenames')
163+
}
164+
153165
// Add containers to main view
154166
this.mainView.appendChild(this.imagesContainer)
155167
this.container.appendChild(this.mainView)
@@ -282,6 +294,9 @@ class CloudImageCarousel {
282294
// Create a document fragment for better performance
283295
const fragment = document.createDocumentFragment()
284296

297+
// Set the alignment for the thumbnails container
298+
this.thumbnailsContainer.style.justifyContent = this.options.thumbnailAlignment
299+
285300
this.images.forEach((img, index) => {
286301
const thumb = document.createElement('div')
287302
thumb.classList.add('ci-carousel-thumbnail')
@@ -292,6 +307,7 @@ class CloudImageCarousel {
292307

293308
const thumbImg = new Image()
294309
thumbImg.src = img.src
310+
thumbImg.style.objectFit = this.options.thumbnailFitMode === THUMBNAIL_FIT_MODE.CROP_FIT ? 'cover' : 'contain'
295311
thumb.appendChild(thumbImg)
296312
fragment.appendChild(thumb)
297313
})

src/js/constants/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './events.constants'
22
export * from './controls.constants'
33
export * from './transition.constants'
44
export * from './icons.contants'
5+
export * from './thumbnails.contants'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const THUMBNAIL_FIT_MODE = {
2+
CROP_FIT: 'crop-fit',
3+
FIT: 'fit',
4+
}
5+
6+
const THUMBNAIL_ALIGNMENT = {
7+
LEFT: 'left',
8+
CENTER: 'center',
9+
RIGHT: 'right',
10+
SPACE_EVENLY: 'space-evenly',
11+
SPACE_BETWEEN: 'space-between',
12+
}
13+
14+
export { THUMBNAIL_FIT_MODE, THUMBNAIL_ALIGNMENT }

src/js/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './image.utils.js'
22
export * from './throttling.utils.js'
33
export * from './dom.utils.js'
4+
export * from './validation.utils.js'

0 commit comments

Comments
 (0)