-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
104 lines (95 loc) · 3.52 KB
/
main.js
File metadata and controls
104 lines (95 loc) · 3.52 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
let hamberger = document.getElementById("hamberger");
let navbar = document.querySelector("nav");
let li = document.querySelectorAll("li");
let toTop = document.getElementById("to-Top");
let addedPro = document.querySelectorAll("#addedPro");
let showMore = document.getElementById("showMore");
let buyButton = document.querySelectorAll("#buy");
let mainImg = document.getElementById("mainImg");
let proImg = document.querySelectorAll("#proImg");
let size = document.getElementById("size");
let quantity = document.getElementById("quantity");
let addToCart = document.getElementById("addToCart");
let readButton = document.querySelectorAll("#readButton")
// the toggle button
hamberger.addEventListener('click', () => {
if (window.innerWidth <= 768) {
if (navbar.style.height === "55px") {
navbar.style.height = "55vh";
li.forEach(element => {
element.style.display = 'block';
});
hamberger.classList.remove("fa-bars");
hamberger.classList.add("fa-xmark");
} else {
navbar.style.height = "55px";
li.forEach(element => {
element.style.display = 'none';
});
hamberger.classList.remove("fa-xmark");
hamberger.classList.add("fa-bars");
};
};
});
// back to top button
window.addEventListener("scroll" , () => {
if (window.scrollY > 100) { //checking if the window is scrolling down more than 100px.
toTop.style.display = "block";
}else {
toTop.style.display = "none";
};
});
//checking if we're in the shop page
//the products are in the both pages, it makes an error in the home page because there is no show more button.
if (window.location.pathname === "/shop.html") {
// show more products button
showMore.addEventListener("click" , () => {
addedPro.forEach(element => {
if (element.style.display === "none") {
element.style.display = "block";
showMore.innerText = "show less";
} else {
element.style.display = "none";
showMore.innerText = "show more"
};
});
});
};
// displaying the product details page
if (window.location.pathname === "/shop.html" || window.location.pathname === "/index.html") {
buyButton.forEach(element => {
element.addEventListener("click", () =>{
location.pathname = "/product.html"
})
})
}
// products details, choosing the product color & style
proImg.forEach(element => {
element.addEventListener("click", () => {
mainImg.src = element.src;
});
});
// add to cart button
if (window.location.pathname === "/product.html" ) {
addToCart.addEventListener("click", () => {
if ((size.value !== "Select Size") && (quantity.value<=10 && quantity.value >=1) ) {
location.pathname = "/cart.html"
};
if (size.value === "Select Size") {
alert("Select A Size !")
}else if (quantity.value > 10) {
alert("Maximum 10 items !")
}else if (quantity.value < 1) {
alert("Minimum 1 item !")
};
});
}
// read button
readButton.forEach(element => {
element.addEventListener("mousedown",() => {
element.style.transform = "translate3d(0, 0, 10px)"
});
element.addEventListener("mouseup",() => {
element.style.transform = "translate3d(-4px, -4px, 10px)"
});
})