-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
83 lines (73 loc) · 2.22 KB
/
main.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
const swiper = new Swiper(".mySwiper", {
slidesPerView: 4,
spaceBetween: 30,
width: 284 * 4.3,
pagination: {
el: ".swiper-pagination",
clickable: true,
}
})
const hamburgerButtonEl = document.getElementById('hamburger-button');
const menuEl = document.querySelector('.menu')
function handleHamburgerButtonClick(event) {
if (!menuEl) return;
const isHidden = menuEl.classList.contains('d-none');
if (!isHidden) {
menuEl.classList.remove('d-flex')
menuEl.classList.add('d-none')
} else {
menuEl.classList.remove('d-none')
menuEl.classList.add('d-flex')
}
}
if (hamburgerButtonEl) {
hamburgerButtonEl.addEventListener('click', handleHamburgerButtonClick)
}
document.addEventListener("DOMContentLoaded", function () {
const slider = document.querySelector(".slider");
const slides = document.querySelectorAll(".slide");
const prevBtn = document.getElementById("prev-btn");
const nextBtn = document.getElementById("next-btn");
let currentIndex = 0;
// Başlangıçta ilk slaytı göster
slides[currentIndex].style.display = "block";
prevBtn.addEventListener("click", function () {
// currentIndex = 1
if (currentIndex > 0) {
slides[currentIndex].style.display = "none";
currentIndex--;
// currentIndex = 0
slides[currentIndex].style.display = "block";
} else {
// currentIndex = 0
currentIndex = slides.length - 1;
// currentIndex = 3
for (let index = 0; index < slides.length; index++) {
const slide = slides[index];
if (index === currentIndex) {
slide.style.display = 'block';
} else {
slide.style.display = 'none';
}
}
}
});
nextBtn.addEventListener("click", function () {
// // currentIndex = 0
if (currentIndex < slides.length - 1) {
slides[currentIndex].style.display = "none";
currentIndex++;
slides[currentIndex].style.display = "block";
} else {
currentIndex = 0;
for (let index = 0; index < slides.length; index++) {
const slide = slides[index];
if (index === currentIndex) {
slide.style.display = 'block';
} else {
slide.style.display = 'none';
}
}
}
});
});