-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ts
44 lines (39 loc) · 1.29 KB
/
script.ts
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
// script.ts
// TypeScript code for handling the hamburger button click
var hamburgerButton = document.getElementById('hamburger');
var mobileLinks = document.getElementById('mobile-links') as HTMLDivElement;
if (hamburgerButton && mobileLinks) {
hamburgerButton.addEventListener('click', () => {
mobileLinks.classList.toggle('hidden');
});
}
var currentSlideID: number = 1;
var sliderElement: HTMLElement | null = document.getElementById('slider');
var totalSlides: number = sliderElement ? sliderElement.childElementCount : 0;
function next(): void {
if (currentSlideID < totalSlides) {
currentSlideID++;
showSlide();
}
}
function prev(): void {
if (currentSlideID > 1) {
currentSlideID--;
showSlide();
}
}
function showSlide(): void {
const slides: HTMLCollectionOf<HTMLLIElement> | undefined = sliderElement?.getElementsByTagName('li');
if (slides) {
for (let index = 0; index < totalSlides; index++) {
const element: HTMLLIElement | undefined = slides[index];
if (element) {
if (currentSlideID === index + 1) {
element.classList.remove('hidden');
} else {
element.classList.add('hidden');
}
}
}
}
}