-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider4.js
178 lines (167 loc) · 5.03 KB
/
slider4.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
let slider4Data = [
{
name: "AMD Rayzon 5 5600X 3 GHZ Desktop Processor",
price: 38256,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/19-118-231-V04.jpg",
rating: "",
},
{
name: "Arctic silver AS%-3.G Thermal Compound",
price: 716,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/83-360-190-01.jpg",
rating: "",
},
{
name: "Western Digital WD black SN750 NVMe M > 2 1 TB ...",
price: 11663,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/29-102-109-V01.jpg",
},
{
name: "Western Digital WD NVMe M>2 2280 1 TB static Drive",
price: 7919,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/14-137-054-07.jpg",
},
{
name: "SAMSUNG 870 EVO Sereies 2.5 SATA internal solid state ",
price: 14091,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/20-232-091-04.jpg",
},
{
name: "WD Blue 3D NAND 1TB Internal 6GB/s 2.5 SSD",
price: 9719,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/14-500-515-V01.jpg",
},
{
name: "GIGBATE G27Q 27 144Hz 144Hz 1440P Gaming Monitor",
price: 26973,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/13-157-937-V01.jpg",
},
{
name: "AMD Rayzon 5 5600X 3 GHZ Desktop Processor",
price: 38256,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/19-118-231-V04.jpg",
rating: "",
},
{
name: "Arctic silver AS%-3.G Thermal Compound",
price: 716,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/83-360-190-01.jpg",
rating: "",
},
{
name: "Western Digital WD black SN750 NVMe M > 2 1 TB ...",
price: 11663,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/29-102-109-V01.jpg",
},
{
name: "Western Digital WD NVMe M>2 2280 1 TB static Drive",
price: 7919,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/14-137-054-07.jpg",
},
{
name: "SAMSUNG 870 EVO Sereies 2.5 SATA internal solid state ",
price: 14091,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/20-232-091-04.jpg",
},
{
name: "WD Blue 3D NAND 1TB Internal 6GB/s 2.5 SSD",
price: 9719,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/14-500-515-V01.jpg",
},
{
name: "GIGBATE G27Q 27 144Hz 144Hz 1440P Gaming Monitor",
price: 26973,
img: "https://c1.neweggimages.com/ProductImageCompressAll300/13-157-937-V01.jpg",
},
];
if (localStorage.getItem("slider4Data") == null) {
localStorage.setItem("slider4Data", JSON.stringify(slider4Data));
}
function appendpro() {
let data = JSON.parse(localStorage.getItem("slider4Data"));
let mainDiv = document.getElementById("slider4_products");
data.forEach(function (el) {
let div = document.createElement("div");
let p_name = document.createElement("p");
p_name.innerHTML = el.name;
p_name.style.fontSize = "14px";
p_name.style.color = "Black";
p_name.style.padding = "0";
p_name.style.overflow = "hidden";
p_name.setAttribute("class", "Tname");
let rating = document.createElement("p");
rating.setAttribute("id", "rateT");
rating.innerHTML = `<p><i class="fas fa-egg"></i><i class="fas fa-egg"></i><i class="fas fa-egg"></i><i class="fas fa-egg"></i><i class="fas fa-egg"></i><span> ( ${Math.round(
Math.random() * 1000
)} )</span></p>`;
let p_Price = document.createElement("ul");
p_Price.innerHTML = "₹ " + el.price;
p_Price.style.fontSize = "22px";
p_Price.setAttribute("class", "Tprice");
let img = document.createElement("img");
img.src = el.img;
div.append(img, rating, p_name, p_Price);
mainDiv.append(div);
// img.addEventListener("click", function () {
// window.location.href = "producdetail.html";
// });
div.addEventListener("click", function () {
window.location.href = "showProductdetails.html";
showdetail(el);
});
});
}
appendpro();
// onclikc event for slider
function slider() {
let sapn = document.getElementById("slider4").getElementsByTagName("span");
let div = document.getElementById("slider4").getElementsByTagName("div");
let l = 0;
sapn[1].onclick = () => {
l++; //for right scroll
for (var i of div) {
if (l == 0) {
i.style.left = "0px";
}
if (l == 1) {
i.style.left = "-740px";
}
if (l == 2) {
i.style.left = "-1480px";
}
if (l == 3) {
i.style.left = "-2220px";
}
if (l == 4) {
i.style.left = "-2967px";
}
if (l > 4) {
l = 4;
}
}
};
sapn[0].onclick = () => {
l--; //for left scroll
for (var i of div) {
if (l == 0) {
i.style.left = "0px";
}
if (l == 1) {
i.style.left = "-740px";
}
if (l == 2) {
i.style.left = "-1480px";
}
if (l == 3) {
i.style.left = "-2220px";
}
if (l < 0) {
l = 0;
}
}
};
}
slider();
function showdetail(el) {
localStorage.setItem("prodetaails", JSON.stringify(el));
}