-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathmain.js
More file actions
42 lines (34 loc) · 1.3 KB
/
main.js
File metadata and controls
42 lines (34 loc) · 1.3 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
const menuToggle = document.getElementById('menuToggle');
const menuList = document.getElementById('menuList');
const menuChild = document.querySelector('.icon span:nth-child(2)')
// عند الضغط على الأيقونة، يظهر أو يختفي
menuToggle.addEventListener('click', (e) => {
e.stopPropagation(); // يمنع غلق القائمة فوراً عند الضغط على الأيقونة
menuList.classList.toggle('show');
menuChild.classList.toggle('show');
});
// إذا ضغط المستخدم في أي مكان آخر، نخفي القائمة
document.addEventListener('click', (e) => {
if (!menuList.contains(e.target) && !menuToggle.contains(e.target)) {
menuList.classList.remove('show');
menuChild.classList.toggle('show');
}
});
//
// زر الرجوع للأعلى
const backToTopBtn = document.getElementById("backToTop");
// عند التمرير لأسفل 700px نظهر الزر
window.addEventListener("scroll", () => {
if (window.scrollY > 700) {
backToTopBtn.style.display = "block";
} else {
backToTopBtn.style.display = "none";
}
});
// عند الضغط على الزر نصعد لأعلى بسلاسة
backToTopBtn.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});