-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
314 lines (267 loc) · 8.45 KB
/
Copy pathscript.js
File metadata and controls
314 lines (267 loc) · 8.45 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
* Siemens Hero JS
*
*
*/
var animation = {
animationTime: 2000,
animationDelay: 5000
};
var sliderElements = [
{
animation: {
delay: 5000
}
},
{
animation: {
delay: 5000
}
},
{
animation: {
delay: 3000
}
},
{
animation: {
delay: 5000
}
},
{
animation: {
delay: 3000
}
},
{
animation: {
delay: 5000
}
},
{
animation: {
delay: 3000
}
}
];
document.addEventListener("DOMContentLoaded", function (event) {
// get the hero element
var hero = document.getElementById("samm-hero-slider");
// get the hero images
var slides = hero.getElementsByClassName("slide");
let _activeIndex = 0;
const activeIndex = {
get index() {
return _activeIndex;
},
set index(value) {
_activeIndex = value;
updatePillContainer();
}
};
const pills = hero.getElementsByClassName("pill");
function updatePillContainer() {
for (let i = 0; i < pills.length; i++) {
const pill = pills[i];
if (i === activeIndex.index) {
pill.classList.add("active");
} else {
pill.classList.remove("active");
}
}
}
Array.from(pills).forEach((pill, index) => {
pill.addEventListener("click", () => {
setAnimationToIndex(activeIndex.index, index);
activeIndex.index = index;
});
});
var numberOfSlides = slides.length; // the number of slides
function triggerAnimation() {
var prevSlide =
slides[(activeIndex.index - 1 + numberOfSlides) % numberOfSlides];
var currentSlide = slides[activeIndex.index];
var nextSlideOuter = slides[(activeIndex.index + 1) % numberOfSlides];
var nextSlideInner = nextSlideOuter.getElementsByTagName("div")[0];
var slideAfterNextSlideInner = slides[
(activeIndex.index + 2) % numberOfSlides
].getElementsByTagName("div")[0];
var slideAfterNextSlideOuter =
slides[(activeIndex.index + 2) % numberOfSlides];
// set the z-index of the previous slide to 0
prevSlide.classList.remove("prev");
prevSlide.classList.add("other");
// move the sliderAfterNextSlide to the start position
slideAfterNextSlideInner.classList.remove("transform-inner-end");
slideAfterNextSlideInner.classList.add("transform-inner-start");
slideAfterNextSlideOuter.classList.remove("transform-outer-end");
slideAfterNextSlideOuter.classList.add("transform-outer-start");
// set the zIndex of the current slide to 1
currentSlide.classList.remove("next");
currentSlide.classList.add("prev");
// set the zIndex of the next slide to 2
nextSlideOuter.classList.remove("other");
nextSlideOuter.classList.add("next");
// start the animation
nextSlideInner.classList.remove("transform-inner-start");
nextSlideInner.classList.add("transform-inner-end");
nextSlideOuter.classList.remove("transform-outer-start");
nextSlideOuter.classList.add("transform-outer-end");
// update the activeIndex
activeIndex.index = (activeIndex.index + 1) % numberOfSlides;
stopInterval();
startInterval(sliderElements[activeIndex.index].animation.delay);
}
function stopAnimations() {
for (let i = 0; i < slides.length; i++) {
const slide = slides[i];
const slideInner = slide.getElementsByTagName("div")[0];
slide.classList.remove("anim");
slideInner.classList.remove("anim");
}
}
function startAnimations() {
for (let i = 0; i < slides.length; i++) {
const slide = slides[i];
const slideInner = slide.getElementsByTagName("div")[0];
slide.classList.add("anim");
slideInner.classList.add("anim");
}
}
function setAnimationToIndex(oldIndex, newIndex) {
stopInterval();
stopAnimations();
if (oldIndex === newIndex) {
startAnimations();
startInterval();
return;
}
// position newIndex slide
const newSlide = slides[newIndex];
const newSlideInner = newSlide.getElementsByTagName("div")[0];
// z-index
newSlide.classList.remove("other");
newSlide.classList.remove("prev");
newSlide.classList.add("next");
const oldNextSlide = slides[(oldIndex + 1) % numberOfSlides];
oldNextSlide.classList.remove("next");
oldNextSlide.classList.remove("prev");
oldNextSlide.classList.add("other");
newSlide.classList.remove("transform-outer-start");
newSlide.classList.add("transform-outer-end");
newSlideInner.classList.remove("transform-inner-start");
newSlideInner.classList.add("transform-inner-end");
const oldPrevSlide = slides[(oldIndex - 1 + numberOfSlides) % numberOfSlides];
oldPrevSlide.classList.remove("next");
oldPrevSlide.classList.remove("prev");
oldPrevSlide.classList.add("other");
// position oldIndex slide
const oldSlide = slides[oldIndex];
const oldSlideInner = oldSlide.getElementsByTagName("div")[0];
oldSlide.classList.remove("prev");
oldSlide.classList.remove('next')
oldSlide.classList.add("other");
// move oldSlide to end position
oldSlide.classList.remove("transform-outer-start");
oldSlide.classList.add("transform-outer-end");
oldSlideInner.classList.remove("transform-inner-start");
oldSlideInner.classList.add("transform-inner-end");
const nextSlideOuter = slides[(newIndex + 1) % numberOfSlides];
const nextSlideInner = nextSlideOuter.getElementsByTagName("div")[0];
// move nextSlide to start position
nextSlideInner.classList.remove("transform-inner-end");
nextSlideInner.classList.add("transform-inner-start");
nextSlideOuter.classList.remove("transform-outer-end");
nextSlideOuter.classList.add("transform-outer-start");
// set newSlide to prev
newSlide.classList.add("prev");
newSlide.classList.remove("other");
newSlide.classList.remove("next");
// set nextSlide to next
nextSlideOuter.classList.add("next");
nextSlideOuter.classList.remove("other");
nextSlideOuter.classList.remove("prev");
// restart Animations
setTimeout(() => {
startAnimations();
}, 500);
startInterval();
}
let isRunning = false;
let animationIntervalId = null;
function startInterval(delay) {
if (!isRunning) {
animationIntervalId = setInterval(
triggerAnimation,
delay || animation.animationDelay
);
isRunning = true;
}
}
function stopInterval() {
if (isRunning) {
clearInterval(animationIntervalId);
isRunning = false;
}
}
const initialLoadIsMobile = window.innerWidth < 781
!initialLoadIsMobile && startInterval()
const maxWidthText = window.innerWidth * (2 / 3 - 1 / 2 ) + 945 / 2 - 64;
const titleDivs = hero.getElementsByClassName("title");
Array.from(titleDivs).forEach((titleDiv) => {
titleDiv.style.maxWidth = `${maxWidthText}px`;
});
// eventlistener on resize
window.addEventListener("resize", function () {
// if window size is smaller than 1025px stop Interval if it is running
if (window.innerWidth < 781) {
stopInterval();
return;
}
else startInterval();
const maxWidthText = window.innerWidth * (2 / 3 - 1 / 2 ) + 945 / 2 - 64;
const titleDivs = hero.getElementsByClassName("title");
Array.from(titleDivs).forEach((titleDiv) => {
titleDiv.style.maxWidth = `${maxWidthText}px`;
});
});
let isMobile = window.innerWidth < 781
// after 500 ms start the animation
setTimeout(() => {
if (isMobile) {
Array.from(hero.getElementsByClassName('big-slide')).forEach((slide) => {
slide.classList.add('transition')
slide.classList.add('trans-mobile')
})
}
}, 500);
window.addEventListener('resize', () => {
if (window.innerWidth < 781) {
if (!isMobile) {
Array.from(hero.getElementsByClassName('big-slide')).forEach((slide) => {
slide.classList.add('transition')
slide.classList.add('trans-mobile')
})
}
isMobile = true
} else {
if (isMobile) {
Array.from(hero.getElementsByClassName('big-slide')).forEach((slide) => {
slide.classList.remove('transition')
slide.classList.remove('trans-mobile')
})
isMobile = false
}
}
})
const arrowDownButton = hero.getElementsByClassName("arrow-down-button")[0];
arrowDownButton &&
arrowDownButton.addEventListener("click", function () {
console.log('asdf')
const heroHeight = hero.clientHeight;
window.scrollTo({
top: heroHeight + 80,
behavior: "smooth",
});
});
});