-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (39 loc) · 1.48 KB
/
script.js
File metadata and controls
47 lines (39 loc) · 1.48 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
document.addEventListener('DOMContentLoaded', function() {
// Existing hamburger menu functionality
const hamburger = document.querySelector('.hamburger-menu');
const navbar = document.querySelector('.navbar');
hamburger.addEventListener('click', function() {
hamburger.classList.toggle('active');
navbar.classList.toggle('active');
});
document.querySelectorAll('.navbar a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navbar.classList.remove('active');
});
});
// New carousel functionality
const carousel = document.querySelector('.carousel');
const items = carousel.querySelectorAll('.carousel-item');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
let currentIndex = 0;
function showItem(index) {
carousel.style.transform = `translateX(-${index * 100}%)`;
}
prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + items.length) % items.length;
showItem(currentIndex);
});
nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % items.length;
showItem(currentIndex);
});
// Optional: Auto-play functionality
function autoPlay() {
currentIndex = (currentIndex + 1) % items.length;
showItem(currentIndex);
}
// Uncomment the next line to enable auto-play
// setInterval(autoPlay, 5000); // Change slide every 5 seconds
});