-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProductDetailPage.js
163 lines (122 loc) · 4.56 KB
/
ProductDetailPage.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
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
// navbar show search dropdown Option
document.querySelector(".searchbar").addEventListener("click", showsearch);
function showsearch(){
document.querySelector("#searchform").style.display = "block";
}
// navbar hide search dropdown Option
document.querySelector(".hidebar").addEventListener("click", closesearch);
function closesearch(){
document.querySelector("#searchform").style.display = "none";
}
// navbar search SUBMIT button function
document.querySelector("form").addEventListener("submit", showproduct);
function showproduct(event){
event.preventDefault();
var searchInput = document.querySelector(".typeany").value;
if(searchInput == "ALL FRUITS"){
window.location.href = "ProductPage.html";
}
}
// function for go to home page.
document.querySelector(".navbar > div:nth-child(1) + img").addEventListener("click", function(){
window.location.href = "index.html";
})
// function for go to log-in page
document.querySelector(".gotologin").addEventListener("click", function(){
window.location.href = "Signin.html";
})
// function for go to cart page
document.querySelector(".gotocart").addEventListener("click", function(){
window.location.href = "cart.html";
})
// window.onscroll = function () {
// myFunction();
// // footFunction();
// };
// var header = document.getElementById("myHeader");
// // var sticky = header.offsetTop;
// // var footer = document.getElementsById("footer");
// function myFunction() {
// if (window.pageYOffset > 100) {
// header.classList.add("sticky");
// } else {
// header.classList.remove("sticky");
// }
// }
// function footFunction() {
// if (window.pageYOffset > 300) {
// footer.classList.add("sticky_footer");
// } else {
// footer.classList.remove("sticky_footer");
// }
// }
// const pack=document.querySelector('.pp');
// pack.addEventListener("mouseover",addPack)
// const addPack=function(){
// pack.classList.toggle("image_underline")
// }
const btnRight = document.querySelector(".right");
const btnLeft = document.querySelector(".left");
let currSlide = 0;
const slides = document.querySelectorAll(".product");
const maxSlide = slides.length;
const goToSlide = function (slide) {
slides.forEach(
(s, i) => (s.style.transform = `translateX(${100 * (i - slide)}%)`)
);
};
goToSlide(0);
const nextSlide = function () {
console.log("right", currSlide);
if (currSlide == maxSlide - 1) {
currSlide = 0;
} else {
currSlide++;
}
goToSlide(currSlide);
};
const prevSlide = function () {
console.log("left", currSlide);
if (currSlide == 0) {
currSlide = maxSlide - 1;
} else {
currSlide--;
}
goToSlide(currSlide);
};
btnRight.addEventListener("click", nextSlide);
btnLeft.addEventListener("click", prevSlide);
// type="module"
// src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"
// nomodule
// src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"
// function for qty minus and plus
var numberplus = document.querySelector(".number").textContent;
document.querySelector(".minus").addEventListener("click", function(){
if(numberplus <= 0){
document.querySelector(".minus").addEventListener("click");
}
numberplus = +numberplus - 1;
document.querySelector(".number").textContent = numberplus;
})
document.querySelector(".plus").addEventListener("click", function(){
numberplus = +numberplus + 1;
document.querySelector(".number").textContent = numberplus;
})
// function for cartdata
document.querySelector(".add").addEventListener("click", additems);
var cartData = [];
function additems(){
var name = document.querySelector(".product_name").textContent;
var pac = document.querySelector(".packvalue").textContent;
var price = document.querySelector(".price").textContent;
var qty = document.querySelector(".number").textContent;
var details = {
name: name,
packs: pac,
price: price,
qty: qty
};
cartData.push(details);
localStorage.setItem("cartDetails", JSON.stringify(cartData));
}