-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazon.js
More file actions
174 lines (145 loc) · 5.58 KB
/
amazon.js
File metadata and controls
174 lines (145 loc) · 5.58 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
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
let fo = document.querySelector('.for');
let elementstomove = document.querySelectorAll('.leftright');
let i = 0;
let j = 0;
function transright() {
if(i==-120)
{
lo.style.backgroundColor = "gray";
lo.style.transitionDuration = '0.3s';
setTimeout(function() {
lo.style.backgroundColor = ""; // set it back to the original color (or another color if needed)
}, 200); // 1000 milliseconds = 1 second
return
}
i -= 40; // Use a fixed value for consistent movement
for (const iterator of elementstomove) {
iterator.style.transform = `translateX(${i}vw)`;
iterator.style.transitionDuration = '0.5s';
}
}
fo.addEventListener('click', transleft);
let lo = document.querySelectorAll('.for')[1];
function transleft() {
if(i==0)
{fo.style.backgroundColor = "gray";
fo.style.transitionDuration = '0.3s';
setTimeout(function() {
fo.style.backgroundColor = ""; // set it back to the original color (or another color if needed)
}, 200);
return
}
i += 40; // Use a fixed value for consistent movement
for (const iterator of elementstomove) {
iterator.style.transform = `translateX(${i}vw)`;
iterator.style.transitionDuration = '0.5s';
}
}
lo.addEventListener('click', transright);
let back=document.querySelector('#back')
back.addEventListener('click',()=>{
window.scrollTo({
top: 0,
behavior: 'smooth'
})
})
let sidebar=document.querySelector('.sidebar')
// sidebar.addEventListener('mouseenter',()=>{
// sidebar.parentElement.style.overflow="hidden"
// })
// sidebar.addEventListener('mouseleave',()=>{
// sidebar.parentElement.style.overflow=""
// })
let seeall = document.querySelectorAll('.seeall')[0];
let l = 0;
// Create and append newdiv1 to newdiv5 initially
let newdiv1 = document.createElement("div");
newdiv1.className = "sidebarcont marg";
newdiv1.innerHTML = "Home, Kitchen, Pets";
let newdiv2 = document.createElement("div");
newdiv2.className = "sidebarcont marg";
newdiv2.innerHTML = "Beauty, Health, Grocery";
let newdiv3 = document.createElement("div");
newdiv3.className = "sidebarcont marg";
newdiv3.innerHTML = "Sports, Fitness, Bags, Luggage";
let newdiv4 = document.createElement("div");
newdiv4.className = "sidebarcont marg";
newdiv4.innerHTML = "asdhasdj";
let newdiv5 = document.createElement("div");
newdiv5.className = "sidebarcont marg";
newdiv5.innerHTML = "Books";
newdiv1.style.display = "none";
newdiv2.style.display = "none";
newdiv3.style.display = "none";
newdiv4.style.display = "none";
newdiv5.style.display = "none";
// Append the elements initially with display: none
seeall.insertAdjacentElement('afterend', newdiv1);
seeall.insertAdjacentElement('afterend', newdiv2);
seeall.insertAdjacentElement('afterend', newdiv3);
seeall.insertAdjacentElement('afterend', newdiv4);
seeall.insertAdjacentElement('afterend', newdiv5);
seeall.addEventListener('click', () => {
l++;
if (l % 2 !== 0) {
seeall.innerHTML = "See Less";
seeall.style.backgroundColor = "#f2f2f2";
seeall.addEventListener('mouseenter', () => {
seeall.style.backgroundColor = "#f2f2f2";
});
seeall.addEventListener('mouseleave', () => {
seeall.style.backgroundColor = "#f2f2f2";
});
}
if (l % 2 === 0) {
seeall.innerHTML = 'See All <img src="down.png" alt="">';
seeall.style.backgroundColor = "#ffffff";
seeall.addEventListener('mouseenter', () => {
seeall.style.backgroundColor = "#f2f2f2";
});
seeall.addEventListener('mouseleave', () => {
seeall.style.backgroundColor = "#ffffff";
});
}
// Toggle the display property on every click
newdiv1.style.display = l % 2 === 0 ? "none" : "block";
newdiv2.style.display = l % 2 === 0 ? "none" : "block";
newdiv3.style.display = l % 2 === 0 ? "none" : "block";
newdiv4.style.display = l % 2 === 0 ? "none" : "block";
newdiv5.style.display = l % 2 === 0 ? "none" : "block";
});
const all=document.querySelector("#all")
let sidebarisout=false;
all.addEventListener('click',()=>{
console.log('it is out')
sidebarisout=true;
// sidebar.style.transform = 'translateX(35vw)';
sidebar.classList.remove('transxneg');
sidebar.classList.add('transx');
cards.style.filter="brightness(0.4)"
caroimg.style.filter="brightness(0.4)"
caroimg2.style.filter="brightness(0.4)"
caroimg3.style.filter="brightness(0.4)"
leftrightcard.style.filter="brightness(0.4)"
sidebar.parentElement.style.overflow="hidden"
})
let caroimg=document.querySelectorAll('.d-block')[0]
let caroimg2=document.querySelectorAll('.d-block')[1]
let caroimg3=document.querySelectorAll('.d-block')[2]
let bo=document.querySelector('body')
let cards=document.querySelectorAll('.cardholder')[0]
let leftrightcard=document.querySelector('.leftrightcard')
const backimg=document.querySelector('#backimg')
backimg.addEventListener('click',()=>{
// sidebar.style.transform = 'translateX(-25vw)';
sidebar.classList.add('transxneg');
sidebar.classList.remove('transx');
console.log('dffd')
cards.style.filter="brightness(1)"
caroimg.style.filter="brightness(1)"
caroimg2.style.filter="brightness(1)"
caroimg3.style.filter="brightness(1)"
leftrightcard.style.filter="brightness(1)"
sidebarisout=false;
sidebar.parentElement.style.overflow="scroll"
})