-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.js
115 lines (87 loc) · 3.02 KB
/
custom.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
document.addEventListener("DOMContentLoaded", function () {
// * for active link
document.querySelectorAll("nav ul li a").forEach((link) => {
link.addEventListener("click", function () {
document.querySelectorAll("nav ul li a").forEach((link) => {
link.classList.remove("active");
});
this.classList.add("active");
});
});
// * mobile-menu
const hamburgger = document.querySelector(".hamburgger");
const mobilemenu = document.querySelector(".navigation");
const icons = document.querySelectorAll(".hamburgger i");
hamburgger.addEventListener("click", function () {
const isVisible = mobilemenu.getAttribute("data-visible");
if (isVisible === "true") {
mobilemenu.setAttribute("data-visible", "false");
icons[0].setAttribute("data-visible", "true");
icons[1].setAttribute("data-visible", "false");
} else {
mobilemenu.setAttribute("data-visible", "true");
icons[0].setAttribute("data-visible", "false");
icons[1].setAttribute("data-visible", "true");
}
});
//*scrolling
window.addEventListener('scroll', function () {
var nav = document.querySelector('.site-navigation');
if (window.scrollY >= 50) {
if (!nav.classList.contains('nav')) {
nav.classList.add('nav');
}
} else {
if (nav.classList.contains('nav')) {
nav.classList.remove('nav');
}
}
});
//* slides
const banner = document.querySelectorAll(".banner");
const nextButton = document.querySelector(".next");
const prevButton = document.querySelector(".prev");
let currentIndex = 0;
banner[currentIndex].classList.add("active");
function showBanner(index) {
banner.forEach(banner => banner.classList.remove("active"));
banner[index].classList.add("active");
}
nextButton.addEventListener("click", function () {
currentIndex = (currentIndex + 1) % banner.length;
showBanner(currentIndex);
});
prevButton.addEventListener("click", function () {
currentIndex = (currentIndex - 1 + banner.length) % banner.length;
showBanner(currentIndex);
});
// faqs-section
const questions = document.querySelectorAll('.question');
const answers = document.querySelectorAll('.answer');
if (answers.length > 0) {
answers[0].style.display = 'block';
}
questions.forEach((header) => {
header.addEventListener('click', () => {
const content = header.nextElementSibling;
const isVisible = content.style.display === 'block';
answers.forEach(item => {
item.style.display = 'none';
});
if (!isVisible) {
content.style.display = 'block';
}
});
});
document.querySelectorAll('.question > h1').forEach((header) => {
header.addEventListener('click', () => {
const answer = header.nextElementSibling;
document.querySelectorAll('.question > h1').forEach((otherHeader) => {
if (otherHeader !== header) {
otherHeader.classList.remove('active');
}
});
header.classList.add('active');
});
});
});