Skip to content

Commit 7faf180

Browse files
committed
slideshow - added to demo, added root classes, switched "kromaSlideshow" to "kroma-slideshow"
1 parent 35df411 commit 7faf180

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

demo.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,22 @@ <h2 class="text-lg text-primary mb-4">Codeblock Component Showcase</h2>
12931293
</div>
12941294
</div>
12951295
</section>
1296+
<section class="p-6 bg-neutral-50 shadow-md rounded my-6" style="height:clamp(300px,35vw,600px);">
1297+
<div class="kroma-slideshow rounded"
1298+
data-autoscroll="false"
1299+
data-waitime="3000"
1300+
data-hoverpause="true"
1301+
data-scrollingpausetime="2000"
1302+
data-enablearrows="true"
1303+
data-enablebullets="true"
1304+
data-inheritsize="true"
1305+
>
1306+
<img src="https://t3.ftcdn.net/jpg/05/24/43/88/360_F_524438877_PZFzwc5OWJ3MTWQVFfHKwu1DRVMaSgPx.jpg">
1307+
<img src="https://t3.ftcdn.net/jpg/05/85/86/44/360_F_585864419_kgIYUcDQ0yiLOCo1aRjeu7kRxndcoitz.jpg">
1308+
<img src="https://t3.ftcdn.net/jpg/05/64/82/08/360_F_564820811_n9WP1mM43pLiQwLkIA07KF9Hat5vkX2v.jpg">
1309+
<img src="https://t4.ftcdn.net/jpg/05/21/18/03/360_F_521180384_837ZQVtGdBocnKQr5prxWzpjIa64wtgO.jpg">
1310+
</div>
1311+
</section>
12961312
</body>
12971313
<script type="module" src="src/js/main.js"></script>
12981314
<script>

src/css/components/slideshow.css

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
@media (pointer:coarse) {
3-
.arrow {display:none !important;}
3+
.kroma-slideshow .arrow {display:none !important;}
44
}
55

6-
.kromaSlideshow .hidden {display:none !important;}
6+
.kroma-slideshow .hidden {display:none !important;}
77

8-
.kromaSlideshow .arrow {
8+
.kroma-slideshow .arrow {
99
opacity:0;
1010
position: sticky;
1111
top: 0;
@@ -29,56 +29,56 @@
2929
text-align: center;
3030
}
3131

32-
.kromaSlideshow .arrow:before{
32+
.kroma-slideshow .arrow:before{
3333
content:"";
3434
position:absolute;
3535
top:0;
3636
left:-28px;
3737
width:55px;
3838
height:100%;
39-
background: #e2e2e28f;
39+
background: var(--neutral-200);
4040
z-index:-1;
4141
border-radius:100%;
4242
transition: 50ms;
4343
}
4444

45-
.kromaSlideshow .arrow.arrowLeft {
45+
.kroma-slideshow .arrow.arrowLeft {
4646
left: 40px;
4747
}
4848

49-
.kromaSlideshow .arrow.arrowRight {
49+
.kroma-slideshow .arrow.arrowRight {
5050
left: calc(100% - 40px );
5151
}
5252

53-
.kromaSlideshow .arrow:hover {
53+
.kroma-slideshow .arrow:hover {
5454
/* transform: scale(1.05) !important; */
5555
color: #626262;
5656
opacity: 1 !important;
5757
}
5858

59-
.kromaSlideshow .arrow:hover:before {
59+
.kroma-slideshow .arrow:hover:before {
6060
-webkit-backdrop-filter: blur(4px);
6161
backdrop-filter: blur(4px);
6262
}
6363

64-
.kromaSlideshow:has(.arrow):hover > .arrow {
64+
.kroma-slideshow:has(.arrow):hover > .arrow {
6565
opacity: 0.8;
6666
display: flex;
6767
align-content: center;
6868
justify-content: center;
6969
align-items: center;
7070
}
7171

72-
.kromaSlideshow:has(.arrow)::-webkit-scrollbar,.kromaSlideshow::-webkit-scrollbar {
72+
.kroma-slideshow:has(.arrow)::-webkit-scrollbar,.kroma-slideshow::-webkit-scrollbar {
7373
display: none;
7474
}
7575

76-
.kromaSlideshow:has(.arrow),.kromaSlideshow {
76+
.kroma-slideshow:has(.arrow),.kroma-slideshow {
7777
-ms-overflow-style: none; /* IE and Edge */
7878
scrollbar-width: none; /* Firefox */
7979
}
8080

81-
.kromaSlideshow {
81+
.kroma-slideshow {
8282
width: 75vw;
8383
height: 35vw;
8484
display: flex;
@@ -90,12 +90,12 @@
9090
scroll-behavior: smooth;
9191
}
9292

93-
.kromaSlideshow.inheritsize{
93+
.kroma-slideshow.inheritsize{
9494
width:100% !important;
9595
height:100% !important;
9696
}
9797

98-
.kromaSlideshow .slide {
98+
.kroma-slideshow .slide {
9999
width: 100%;
100100
height: 100%;
101101
background-size: cover !important;
@@ -105,21 +105,21 @@
105105
scroll-snap-align: center;
106106
}
107107

108-
.kromaSlideshow .slide.first {
108+
.kroma-slideshow .slide.first {
109109
border-top-left-radius: inherit;
110110
border-bottom-left-radius: inherit;
111111
}
112112

113-
.kromaSlideshow .slide.last {
113+
.kroma-slideshow .slide.last {
114114
border-top-right-radius: inherit;
115115
border-bottom-right-radius: inherit;
116116
}
117117

118-
.kromaSlideshow .bullets {
118+
.kroma-slideshow .bullets {
119119
position: sticky;
120120
margin-bottom: 7px;
121121
margin-top: auto;
122-
background: #2f2f2fbd;
122+
background: var(--neutral-100);
123123
width: max-content;
124124
height: max-content;
125125
display: flex;
@@ -131,14 +131,20 @@
131131
opacity: 0.8;
132132
}
133133

134-
.kromaSlideshow .bullet {
134+
.kroma-slideshow .bullet {
135135
width: 15px;
136136
height: 15px;
137-
background: #ffffff69;
137+
background: var(--neutral-600);
138138
border-radius: 51px;
139139
cursor:pointer;
140140
}
141141

142-
.kromaSlideshow .bullet.current {
143-
background: white;
142+
.kroma-slideshow .bullet.current {
143+
background: var(--neutral-900);
144144
}
145+
146+
147+
.kroma-slideshow .arrow i {
148+
font-size: 25px;
149+
color: var(--neutral-800);
150+
}

src/js/components/slideshow.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ export class KromaSlideshow {
1313
1414
requires basic preexisting html structure with desired data, such as:
1515
16-
<div class="kromaSlideshow">
16+
<div class="kroma-slideshow rounded"
17+
data-autoscroll="fase"
18+
data-waitime="3000"
19+
data-hoverpause="true"
20+
data-scrollingpausetime="2000"
21+
data-enablearrows="true"
22+
data-enablebullets="true"
23+
data-inheritsize="true"
24+
>
1725
1826
<img src="https://t3.ftcdn.net/jpg/05/24/43/88/360_F_524438877_PZFzwc5OWJ3MTWQVFfHKwu1DRVMaSgPx.jpg">
1927
<img src="https://t3.ftcdn.net/jpg/05/85/86/44/360_F_585864419_kgIYUcDQ0yiLOCo1aRjeu7kRxndcoitz.jpg">
@@ -32,9 +40,8 @@ export class KromaSlideshow {
3240
this.id = id;
3341
this.cnt_sld = document.getElementById(id);
3442
if(!this.cnt_sld){ throw new Error(`element "${id}" not found`); }
35-
//if(this.cnt_sld.classList.contains('kromaSlideshow')){ throw new Error(`slideshow already set.`); }
36-
//this.cnt_sld.classList.add('slideshow');
37-
//this.cnt_sld.classList.add('kromaSlideshow');
43+
if(this.cnt_sld.classList.contains('kroma-slideshow-set')){ throw new Error(`slideshow already set.`); }
44+
this.cnt_sld.classList.add('kroma-slideshow-set');
3845

3946

4047
//get parameters from call if passed else from element dataset if available else default
@@ -56,16 +63,22 @@ export class KromaSlideshow {
5663
if(this.enableArrows && prvSlds.length>1){
5764

5865
var arrowLeft = document.createElement('div');
66+
var arrowLeftIcon = document.createElement('i');
5967
arrowLeft.classList.add('arrow');
6068
arrowLeft.classList.add('arrowLeft');
6169
arrowLeft.classList.add('hidden');
62-
arrowLeft.innerHTML = '<';
70+
arrowLeftIcon.classList.add('fa-solid');
71+
arrowLeftIcon.classList.add('fa-chevron-left');
72+
arrowLeft.appendChild(arrowLeftIcon);
6373

6474
var arrowRight = document.createElement('div');
75+
var arrowRightIcon = document.createElement('i');
6576
arrowRight.classList.add('arrow');
6677
arrowRight.classList.add('arrowRight');
6778
arrowRight.classList.add('hidden');
68-
arrowRight.innerHTML = '>';
79+
arrowRightIcon.classList.add('fa-solid');
80+
arrowRightIcon.classList.add('fa-chevron-right');
81+
arrowRight.appendChild(arrowRightIcon);
6982

7083
this.cnt_sld.appendChild(arrowRight);
7184
this.cnt_sld.appendChild(arrowLeft);
@@ -220,7 +233,6 @@ export class KromaSlideshow {
220233
});
221234

222235
//start automatic scroll
223-
console.log(this.autoScroll);
224236
if(this.autoScroll){this.slideAuto();}
225237

226238

@@ -274,10 +286,10 @@ document.addEventListener("DOMContentLoaded", () => {
274286

275287
window.kromaSlideshow = KromaSlideshow;
276288
if(!window.kromaSlideshows){ window.kromaSlideshows = []; }
277-
var domSlideshows = document.querySelectorAll('.kromaSlideshow');
289+
var domSlideshows = document.querySelectorAll('.kroma-slideshow');
278290
if(domSlideshows && domSlideshows[0]){
279291

280-
domSlideshows[0].id = (domSlideshows[0].id ?? '').length > 0 ? domSlideshows[0].id : ( 'kromaSlideshow_' + window.kromaSlideshow.length );
292+
domSlideshows[0].id = (domSlideshows[0].id ?? '').length > 0 ? domSlideshows[0].id : ( 'kroma-slideshow-' + window.kromaSlideshow.length );
281293
window.kromaSlideshow[window.kromaSlideshow.length] = new KromaSlideshow( domSlideshows[0].id );
282294

283295
}

0 commit comments

Comments
 (0)