-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhowto.js
More file actions
48 lines (38 loc) · 1.26 KB
/
howto.js
File metadata and controls
48 lines (38 loc) · 1.26 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
// script.js
let currentIndex = 0;
let totalItems = document.querySelectorAll('.carousel-item').length;
let interval = 3000; // Time between slides in milliseconds
function showSlide(index) {
const carouselInner = document.querySelector('.carousel-inner');
const indicators = document.querySelectorAll('.indicator');
if (index >= totalItems) {
currentIndex = 0;
} else if (index < 0) {
currentIndex = totalItems - 1;
} else {
currentIndex = index;
}
const offset = -currentIndex * 100;
carouselInner.style.transform = `translateY(${offset}%)`;
indicators.forEach((indicator, idx) => {
indicator.classList.toggle('active', idx === currentIndex);
});
}
function nextSlide() {
showSlide(currentIndex + 1);
}
function startCarousel() {
setInterval(nextSlide, interval);
}
// Initialize the first slide and start the carousel
showSlide(currentIndex);
startCarousel();
// Light and dark mode switch functionality
const sunBtn = document.getElementById('sun-btn');
const moonBtn = document.getElementById('moon-btn');
sunBtn.addEventListener('click', () => {
document.body.classList.add('dark-mode');
});
moonBtn.addEventListener('click', () => {
document.body.classList.remove('dark-mode');
});