-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
55 lines (43 loc) · 1.5 KB
/
script.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
const slides = document.querySelectorAll('.carousel-slide');
const dots = document.querySelectorAll('.dot');
let currentIndex = 0;
function showSlide(index) {
const slideWidth = slides[0].clientWidth;
const container = document.querySelector('.carousel-container');
container.style.transform = `translateX(-${index * slideWidth}px)`;
dots.forEach((dot, i) => dot.classList.toggle('active', i === index));
}
function nextSlide() {
currentIndex = (currentIndex + 1) % slides.length;
showSlide(currentIndex);
}
dots.forEach((dot, i) => {
dot.addEventListener('click', () => {
currentIndex = i;
showSlide(currentIndex);
});
});
// Auto-play functionality
setInterval(nextSlide, 5000);
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const storiesWrapper = document.querySelector('.stories-wrapper');
let scrollAmount = 0;
nextBtn.addEventListener('click', () => {
if (scrollAmount < storiesWrapper.scrollWidth - storiesWrapper.clientWidth) {
scrollAmount += 330; // Adjust the scroll distance
storiesWrapper.scrollTo({
left: scrollAmount,
behavior: 'smooth'
});
}
});
prevBtn.addEventListener('click', () => {
if (scrollAmount > 0) {
scrollAmount -= 330; // Adjust the scroll distance
storiesWrapper.scrollTo({
left: scrollAmount,
behavior: 'smooth'
});
}
});