-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase.js
More file actions
227 lines (181 loc) · 6.97 KB
/
case.js
File metadata and controls
227 lines (181 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
class Slideshow {
constructor(sliderId, leftArrowId, rightArrowId, totalSlides) {
this.slider = document.getElementById(sliderId);
this.leftArrow = document.getElementById(leftArrowId);
this.rightArrow = document.getElementById(rightArrowId);
this.totalSlides = totalSlides;
this.index = 0;
this.holders = this.slider.querySelectorAll('holder');
this.init();
}
init() {
this.setIndex();
this.leftArrow.addEventListener('click', () => {
this.prevSlide();
this.changeSvgFill(this.leftArrow);
});
this.rightArrow.addEventListener('click', () => {
this.nextSlide();
this.changeSvgFill(this.rightArrow);
});
}
setIndex() {
const transformPercentage = 100 / this.totalSlides;
this.slider.style.transform = `translate(${this.index * -transformPercentage}%)`;
this.holders.forEach((holder, idx) => {
holder.classList.toggle('current', idx === this.index);
});
setTimeout(() => {
this.updateArrowOpacity();
}, 100);
}
nextSlide() {
this.index = (this.index < this.totalSlides - 1) ? this.index + 1 : 0;
this.setIndex();
}
prevSlide() {
this.index = (this.index > 0) ? this.index - 1 : this.totalSlides - 1;
this.setIndex();
}
changeSvgFill(button) {
const svg = button.querySelector('svg');
if (svg) {
svg.style.fill = '#1D1E1F';
setTimeout(() => {
svg.style.fill = '';
}, 100);
}
}
updateArrowOpacity() {
this.leftArrow.style.opacity = (this.index === 0) ? 0.3 : 1;
this.rightArrow.style.opacity = (this.index === this.totalSlides - 1) ? 0.3 : 1;
}
}
// Instantiate the slideshow
document.addEventListener('DOMContentLoaded', () => {
new Slideshow('Slider', 'leftSlide', 'rightSlide', 8);
new Slideshow('Slider2', 'leftSlide2', 'rightSlide2', 5);
new Slideshow('Slider3', 'leftSlide3', 'rightSlide3', 5);
new Slideshow('Slider4', 'leftSlide4', 'rightSlide4', 3);
new Slideshow('Slider5', 'leftSlide5', 'rightSlide5', 8);
new Slideshow('Slider6', 'leftSlide6', 'rightSlide6', 5);
});
class BackgroundSlideshow {
constructor(containerId, leftArrowId, rightArrowId, textId, totalSlides, imageDetails) {
this.container = document.getElementById(containerId);
this.leftArrow = document.getElementById(leftArrowId);
this.rightArrow = document.getElementById(rightArrowId);
this.textElement = document.getElementById(textId);
this.totalSlides = totalSlides;
this.imageDetails = imageDetails; // Array of objects { url, content }
this.index = 0;
this.init();
}
init() {
this.updateBackground();
this.updateText();
this.leftArrow.addEventListener('click', () => {
this.prevSlide();
this.changeSvgFill(this.leftArrow);
});
this.rightArrow.addEventListener('click', () => {
this.nextSlide();
this.changeSvgFill(this.rightArrow);
});
}
updateBackground() {
const { url } = this.imageDetails[this.index];
if (url) {
this.container.style.backgroundImage = `url(${url})`;
} else {
console.error(`No image URL found for index ${this.index}`);
}
}
updateText() {
const { content } = this.imageDetails[this.index];
if (content && this.textElement) {
this.textElement.innerHTML = content;
}
}
nextSlide() {
this.index = (this.index < this.totalSlides - 1) ? this.index + 1 : 0;
this.updateBackground();
this.updateText();
setTimeout(() => {
this.updateArrowOpacity();
}, 100);
}
prevSlide() {
this.index = (this.index > 0) ? this.index - 1 : this.totalSlides - 1;
this.updateBackground();
this.updateText();
setTimeout(() => {
this.updateArrowOpacity();
}, 100);
}
changeSvgFill(button) {
const svg = button.querySelector('svg');
if (svg) {
svg.style.fill = '#1D1E1F';
setTimeout(() => {
svg.style.fill = '';
}, 100);
}
}
updateArrowOpacity() {
this.leftArrow.style.opacity = (this.index === 0) ? 0.3 : 1;
this.rightArrow.style.opacity = (this.index === this.totalSlides - 1) ? 0.3 : 1;
}
}
// Instantiate the background slideshow
document.addEventListener('DOMContentLoaded', () => {
const cabinetImgs = [
{ url: 'Im/shelf/cabinet-0.webp', content: "<h7><span>Cabinet</span></h7><br>Add as fast as you think, from any and every shelf.<br><br>" },
{ url: 'Im/shelf/cabinet-1.webp', content: "<h7><span>Add from anywhere.</span></h7><br>Tap the cabinet to add, whether on the way to class, a first date, or simply lounging at home." },
{ url: 'Im/shelf/cabinet-2.webp', content: "<h7><span>Two colors. Zero limits.</span></h7><br>Quickly change the look of Shelf with just two colors, which paint every wall and item." },
{ url: 'Im/shelf/cabinet-3.webp', content: "<h7><span>Saved for later.</span></h7><br>Shelf's archive lets you browse and organize your items and bring them back whenever you're ready." },
];
new BackgroundSlideshow('cabinet', 'leftArrow', 'rightArrow', 'cabinetText', cabinetImgs.length, cabinetImgs);
});
class ButtonBasedSlideshow {
constructor(buttonContainerId, targetId) {
this.buttonContainer = document.getElementById(buttonContainerId);
this.target = document.getElementById(targetId);
this.buttons = this.buttonContainer.querySelectorAll('button');
this.init();
}
init() {
this.buttons.forEach(button => {
button.addEventListener('click', () => this.updateSlide(button));
});
this.setDefaultBackground();
}
setDefaultBackground() {
const currentButton = this.buttonContainer.querySelector('button.current');
if (currentButton) {
this.updateSlide(currentButton);
} else if (this.buttons.length > 0) {
this.updateSlide(this.buttons[0]);
}
}
updateSlide(button) {
const imageUrl = button.getAttribute('imageUrl');
if (imageUrl) {
this.target.style.backgroundImage = `url(${imageUrl})`;
this.updateCurrentClass(button);
} else {
console.error(`No image URL found for button`);
}
}
updateCurrentClass(activeButton) {
this.buttons.forEach(button => {
button.classList.remove('current');
});
activeButton.classList.add('current');
}
}
// Instantiate the button-based slideshow
document.addEventListener('DOMContentLoaded', () => {
new ButtonBasedSlideshow('buttonContainer', 'stand');
new ButtonBasedSlideshow('colorContainer', 'family');
});