-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (91 loc) · 2.97 KB
/
index.js
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
let darkMode = localStorage.getItem("darkMode");
function enableDarkMode() {
document.body.classList.add("darkmode");
localStorage.setItem("darkMode", "enabled");
}
function disableDarkMode() {
document.body.classList.remove("darkmode");
localStorage.setItem("darkMode", null);
}
if (darkMode === "enabled") {
enableDarkMode();
}
// Listeners
const darkModeToggle = document.querySelector("#dark-mode-toggle");
darkModeToggle.addEventListener("click", () => {
darkMode = localStorage.getItem("darkMode");
darkMode !== "enabled" ? enableDarkMode() : disableDarkMode();
});
var swiper = new Swiper(".mySwiper", {
slidesPerGroup: 1,
loop: true,
fade: true,
// grabCursor: true,
// loopFillGroupWithBlank: true,
autoplay: {
delay: 4000,
disableOnInteraction: false,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
500: {
slidesPerView: 1,
spaceBetween: 20,
},
868: {
slidesPerView: 2,
spaceBetween: 30,
},
1000: {
slidesPerView: 3,
spaceBetween: 30,
},
1250: {
slidesPerView: 3,
spaceBetween: 30,
},
},
});
const carouselItems = document.querySelectorAll('.carousel-item');
let currentIndex = 0;
const intervalTime = 3000; // Time in milliseconds between slides
function showCarouselItem(index) {
carouselItems.forEach((item, i) => {
item.classList.remove('active');
if (i === index) {
item.classList.add('active');
}
});
}
function nextCarouselItem() {
currentIndex = (currentIndex + 1) % carouselItems.length;
showCarouselItem(currentIndex);
}
// Set interval to auto rotate carousel items
let autoCarousel = setInterval(nextCarouselItem, intervalTime);
// Optionally, stop auto-rotation on hover and restart on mouse leave
const carouselContainer = document.querySelector('.carousel-container');
carouselContainer.addEventListener('mouseenter', () => {
clearInterval(autoCarousel);
});
carouselContainer.addEventListener('mouseleave', () => {
autoCarousel = setInterval(nextCarouselItem, intervalTime);
});
// Initialize the carousel
showCarouselItem(currentIndex);
document.addEventListener("DOMContentLoaded", function() {
// Get all nav-link elements
const navLinks = document.querySelectorAll('.nav-link');
// Loop through each nav-link and add click event listener
navLinks.forEach(link => {
link.addEventListener('click', function() {
// Remove 'active' class from all nav-links
navLinks.forEach(nav => nav.classList.remove('active'));
// Add 'active' class to the clicked nav-link
this.classList.add('active');
});
});
});