-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (38 loc) · 1.37 KB
/
index.js
File metadata and controls
50 lines (38 loc) · 1.37 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
49
50
let currentIndex = 0;
let intervalId;
const startAutoPlay = (intervalTime) => {
intervalId = setInterval(() => {
nextSlide();
}, intervalTime);
};
const stopAutoPlay = () => {
clearInterval(intervalId);
};
startAutoPlay(3000);
const nextSlide = () => {
currentIndex = (currentIndex + 1) % document.querySelectorAll('.carousel-item').length;
updateCarousel();
};
const prevSlide = () => {
const totalItems = document.querySelectorAll('.carousel-item').length;
currentIndex = (currentIndex - 1 + totalItems) % totalItems;
updateCarousel();
};
const updateCarousel = () => {
const carouselInner = document.querySelector('.carousel-inner');
const itemWidth = document.querySelector('.carousel-item').offsetWidth;
const translateValue = -currentIndex * itemWidth;
carouselInner.style.transform = `translateX(${translateValue}px)`;
};
const toggleAnswer = (question) => {
const answer = question.nextElementSibling;
const isOpen = answer.style.display === 'block';
const allQuestions = document.querySelectorAll('.question');
allQuestions.forEach((q) => {
const ans = q.nextElementSibling;
ans.style.display = 'none';
q.querySelector('div').textContent = '▼';
});
answer.style.display = isOpen ? 'none' : 'block';
question.querySelector('div').textContent = isOpen ? '▼' : '▲';
};