-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
183 lines (163 loc) · 6.02 KB
/
Copy pathscript.js
File metadata and controls
183 lines (163 loc) · 6.02 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
document.addEventListener("DOMContentLoaded", function () {
const navbar = document.querySelector(".navbar");
const humburgerIcon = document.getElementById("humburger-icon");
const closeIcon = document.getElementById("close-icon");
const menuToggle = document.querySelector(".menu-toggle");
// Toggle mobile menu
function toggleMobileMenu() {
navbar.classList.toggle("active");
document.body.classList.toggle("no-scroll");
humburgerIcon.style.display = navbar.classList.contains("active")
? "none"
: "block";
closeIcon.style.display = navbar.classList.contains("active")
? "block"
: "none";
}
menuToggle.addEventListener("click", toggleMobileMenu);
// Handle dropdown toggle (khusus untuk mobile)
const topLevelLinks = document.querySelectorAll(".navbar ul > li > a");
topLevelLinks.forEach((link) => {
const dropdown = link.nextElementSibling;
if (dropdown && dropdown.classList.contains("dropdown")) {
link.addEventListener("click", function (e) {
if (window.innerWidth <= 768) {
e.preventDefault();
document.querySelectorAll(".dropdown.show").forEach((d) => {
if (d !== dropdown) d.classList.remove("show");
});
document
.querySelectorAll(".navbar ul > li > a i.bi")
.forEach((icon) => {
if (icon.closest("li").querySelector(".dropdown") !== dropdown) {
icon.classList.remove("bi-caret-up-fill");
icon.classList.add("bi-caret-down-fill");
}
});
dropdown.classList.toggle("show");
const icon = this.querySelector("i.bi");
if (icon) {
icon.classList.toggle(
"bi-caret-up-fill",
dropdown.classList.contains("show")
);
icon.classList.toggle(
"bi-caret-down-fill",
!dropdown.classList.contains("show")
);
}
}
});
}
});
// Klik link biasa menutup menu
navbar.querySelectorAll("a").forEach((link) => {
link.addEventListener("click", function () {
if (window.innerWidth <= 768) {
const isDropdownParent =
link.parentElement && link.parentElement.querySelector(".dropdown");
const isDropdownItem = link.closest(".dropdown");
if (!isDropdownParent || isDropdownItem) {
toggleMobileMenu();
document
.querySelectorAll(".dropdown.show")
.forEach((d) => d.classList.remove("show"));
document.querySelectorAll(".navbar ul li a i.bi").forEach((icon) => {
icon.classList.remove("bi-caret-up-fill");
icon.classList.add("bi-caret-down-fill");
});
}
}
});
});
// Reset jika resize ke desktop
window.addEventListener("resize", () => {
if (window.innerWidth > 768) {
navbar.classList.remove("active");
document.body.classList.remove("no-scroll");
humburgerIcon.style.display = "block";
closeIcon.style.display = "none";
// Reset dropdowns (transisi dari mobile ke desktop)
document
.querySelectorAll(".dropdown.show")
.forEach((d) => d.classList.remove("show"));
document.querySelectorAll(".navbar ul li a i.bi").forEach((icon) => {
icon.classList.remove("bi-caret-up-fill");
icon.classList.add("bi-caret-down-fill");
});
}
});
});
// Buat Logika buat animasi typing text
// buat lah variable array
const text = [
"Shallahuddin Al - Ayyubi Islamic Elementary School",
"Sekolah Islam Terpadu Unggulan diBekasi",
"Sekolah Dasar Islam Terpadu SAAIES Bekasi",
"Sekolah Menengah Pertama Islam Terpadu SAAIES Bekasi",
"Sekolah Menengah Atas Islam Terpadu SAAIES Bekasi",
];
// buat variable yg mengambil element span, berdasarkan id
const typingSpan = document.getElementById("typing-text");
// buat variable yg dimulai dari angka 0 berdasarkan index
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
// buat function utama yg fungsi ny untuk mengatur mengetik dan menghapus
function type() {
// buat variable yg mengambil variable array, dan isi ny variable yg value ny dimulai dari angka/index 0
const currentText = text[textIndex];
// buat pengkondisian if
if (!isDeleting) {
// jika sedang proses mengetik, tampilkan karakter dari awal sampe akhir
// 0 + 1 seterus ny sampai karakter habis
typingSpan.textContent = currentText.slice(0, charIndex + 1);
// increment, menambah satu angka
charIndex++;
// setelah selesai mengetik, maka lanjut menghapus karakter
if (charIndex === currentText.length) {
// maka variable isDeleting bernilai true/benar jika sudah saat ny menghapus karakter
isDeleting = true;
// sebelum menghapus berikan jeda 800 mili second/per detik
setTimeout(type, 800);
return; // kembalikan, agar tidak terlalu kecepatan saat mengetik atau menghapus
}
} else {
// jika sedang menghapus maka kurangi karakter dari dikurang 1
typingSpan.textContent = currentText.slice(0, charIndex - 1);
charIndex--; // menggunakan decrement
// jika sudah habis karakter ny dihapus, maka mulai dari awal lagi mengetik nya
if (charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % text.length;
setTimeout(type, 400); // kasih jeda sebelum mulai mengetik karakter baru lgi
return;
}
}
setTimeout(type, isDeleting ? 40 : 80);
// mengatur kecepatan, 40 mili second/per detik jika sedang menghapus
// mengatur kecepatan, 80 mili second/per detik jika sedang mengetik
}
type(); // memulai animasi typing saat halaman dibuka
// Logika Swiper Javascript untuk halaman home index.html
const swiper = new Swiper(".fasilitas-swiper", {
slidesPerView: 1,
spaceBetween: 20,
loop: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
768: {
slidesPerView: 2,
},
1024: {
slidesPerView: 3,
},
},
});