-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.js
82 lines (77 loc) · 2.13 KB
/
Script.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
// For_Navbar
let navToggler = document.querySelector(".nav-toggler");
navToggler.addEventListener("click", togggleNav);
function togggleNav() {
navToggler.classList.toggle("active");
document.querySelector(".nav").classList.toggle("open");
}
document.addEventListener("click", function (e) {
if (e.target.closest(".nav-items")) {
togggleNav();
}
});
// Sticky_Header
window.addEventListener("scroll", function () {
if (this.pageYOffset > 70) {
document.querySelector(".header").classList.add("sticky");
} else {
document.querySelector(".header").classList.remove("sticky");
}
});
// ForCollection
let allBox = document.querySelectorAll(".card .box");
let AllBtn = document.querySelectorAll(".collection-tabs button");
// console.log(allBox)
AllBtn.forEach((button) => {
button.addEventListener("click", (e) => {
console.log(e.target);
let category = e.target.getAttribute("data-category");
console.log(category);
if (category == "all") {
showBox(allBox);
} else {
let filterBoxes = [];
allBox.forEach((box) => {
// console.log(box);
hideBoxes();
if (box.getAttribute("data-category") == category) {
filterBoxes.push(box);
}
showBox(filterBoxes);
});
}
// console.log(filterBoxes)
});
});
function hideBoxes() {
allBox.forEach((box) => {
box.classList.add("hide");
});
}
function showBox(boxList) {
boxList.forEach((box) => {
box.classList.remove("hide");
});
}
let Tabs = document.querySelector(".collection-tabs");
Tabs.addEventListener("click", function (e) {
if (
e.target.classList.contains("collection-tab-item") &&
!e.target.classList.contains("active")
) {
let target = e.target.getAttribute("data-target");
Tabs.querySelector(".active").classList.remove("active");
e.target.classList.add("active");
}
});
//ForCopyPhoneNumber
function copyPhoneNumber(phoneNumber) {
navigator.clipboard
.writeText(phoneNumber)
.then(() => {
alert("Phone number copied to clipboard: " + phoneNumber);
})
.catch((err) => {
console.error("Error copying phone number: ", err);
});
}