-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
214 lines (158 loc) · 4.65 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Level
const lvl = document.querySelector('.level');
rec()
function rec(count = 1, speed = 30){
lvl.innerHTML = count
if (count > 50) {
speed = 100
}
if (count > 75) {
speed = 200
}
if (count > 90) {
speed = 500
}
if (count != 100) {
setTimeout(() =>
rec(++count), speed
)
}
}
// Product objects
const product = {
gamb: {
name: 'Gamburger',
amount: 0,
price: 10000,
caloria: 100,
get prc(){
return this.amount * this.price
},
get calr(){
return this.amount * this.caloria
}
},
fresh: {
name: 'Gamburger-fresh',
amount: 0,
price: 20500,
caloria: 205,
get prc(){
return this.amount * this.price
},
get calr(){
return this.amount * this.caloria
}
},
combo: {
name: 'fresh-combo',
amount: 0,
price: 31900,
caloria: 319,
get prc(){
return this.amount * this.price
},
get calr(){
return this.amount * this.caloria
}
}
}
// Product Calculate
const plsMnsBtn = document.querySelectorAll('#cardBtn');
for (let i = 0; i < plsMnsBtn.length; i++) {
plsMnsBtn[i].addEventListener('click', function(){
plsOrMns(this);
});
}
function plsOrMns(element){
const card = element.closest('.card'),
cardId = card.getAttribute('id'),
input = card.querySelector('.input'),
price = card.querySelector('.price'),
caloria = card.querySelector('.caloria'),
elmSym = element.getAttribute('data-symbol');
if (elmSym == '+') {
product[cardId].amount++
}
else if(elmSym == '-' && product[cardId].amount > 0){
product[cardId].amount--
}
input.innerHTML = product[cardId].amount
price.innerHTML = product[cardId].prc
caloria.innerHTML = product[cardId].calr
document.querySelector('.gamb__numb').innerHTML = product.gamb.amount
document.querySelector('.fresh__numb').innerHTML = product.fresh.amount
document.querySelector('.combo__numb').innerHTML = product.combo.amount
let ttl = product.gamb.amount + product.fresh.amount + product.combo.amount
document.querySelector('.total').innerHTML = ttl
let ttlPrc = product.gamb.prc + product.fresh.prc + product.combo.prc
document.querySelector('.purchase').innerHTML = ttlPrc
}
// Order
const delv = document.querySelector('.delivery'),
order = document.querySelector('.order__blog'),
cancel = document.querySelector('.fas.fa-times'),
pay = document.querySelector('.pay__button');
delv.addEventListener('click', function(){
order.classList.add('show')
});
cancel.addEventListener('click', function(){
order.classList.remove('show')
});
pay.addEventListener('click', function(){
order.classList.remove('show')
document.querySelector('.pay__info').classList.add('show')
rate.classList.add('show')
});
document.querySelector('#times').addEventListener('click', function(){
document.querySelector('.pay__info').classList.remove('show')
});
// Delivery button
delv.addEventListener('click', function(e){
let x = e.clientX - e.target.offsetLeft;
let y = e.clientY - e.target.offsetTop;
let ripples = document.createElement('span');
ripples.style.left = x + 'px';
// ripples.style.top = y + 'px';
this.appendChild(ripples);
setTimeout(() => {
ripples.remove()
},500);
});
// Slider rate blog
const slider = document.querySelector('.slider input');
const thumb = document.querySelector('.slider .thumb');
const progres = document.querySelector('.slider .progres-bar');
const slideIcon = document.querySelector('#slideIcon');
const rate = document.querySelector('.rate__blog');
const sendBtn = document.querySelector('.send__button');
slider.oninput = ()=>{
let value = slider.value
thumb.style.left = value + '%';
progres.style.width = value + '%';
if (value < 20) {
slideIcon.style.marginLeft = '0px';
}
if (value >= 20) {
slideIcon.style.marginLeft = '-20%';
}
if (value >= 40) {
slideIcon.style.marginLeft = '-40%';
}
if (value >= 60) {
slideIcon.style.marginLeft = '-60%';
}
if (value >= 80) {
slideIcon.style.marginLeft = '-80%';
}
}
sendBtn.addEventListener('click', function(){
rate.classList.remove('show');
});
// Counter-up footer
$(document).ready(function(){
$(".box__numb").counterUp({
// delay: 10,
time: 1000
});
});