-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (62 loc) · 2.52 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
const rangevalue = document.querySelector(".slider-container .price-slider");
const rangeInputvalue = document.querySelectorAll(".range-input input");
let priceGap = 500;
const priceInputvalue = document.querySelectorAll(".price-input input");
for (let i = 0; i < priceInputvalue.length; i++) {
priceInputvalue[i].addEventListener("input", e => {
let minp = parseInt(priceInputvalue[0].value);
let maxp = parseInt(priceInputvalue[1].value);
let diff = maxp - minp
if (minp < 0) {
alert("minimum price cannot be less than 0");
priceInputvalue[0].value = 0;
minp = 0;
}
if (maxp > 10000) {
alert("maximum price cannot be greater than 10000");
priceInputvalue[1].value = 10000;
maxp = 10000;
}
if (minp > maxp - priceGap) {
priceInputvalue[0].value = maxp - priceGap;
minp = maxp - priceGap;
if (minp < 0) {
priceInputvalue[0].value = 0;
minp = 0;
}
}
if (diff >= priceGap && maxp <= rangeInputvalue[1].max) {
if (e.target.className === "min-input") {
rangeInputvalue[0].value = minp;
let value1 = rangeInputvalue[0].max;
rangevalue.stlye.left = `${(minp/value1) * 100}`;
}
else {
rangeInputvalue[1].value = maxp;
let value2 = rangeInputvalue[1].max;
rangevalue.style.right = `${100 - (maxp / value2) * 100}%`;
}
}
});
for (let i = 0; i < rangeInputvalue.length; i++) {
rangeInputvalue[i].addEventListener("input", e => {
let minVal = parseInt(rangeInputvalue[0].value);
let maxVal = parseInt(rangeInputvalue[1].value);
let diff = maxVal - minVal
if (diff < priceGap) {
if (e.target.className === "min-range") {
rangeInputvalue[0].value = maxVal - priceGap;
}
else {
rangeInputvalue[1].value = minVal + priceGap;
}
}
else {
priceInputvalue[0].value = minVal;
priceInputvalue[1].value = maxVal;
rangevalue.style.left = `${(minVal / rangeInputvalue[0].max)*100}%`;
rangevalue.style.right = `${100 - (maxVal/rangeInputvalue[1].max)*100}%`;
}
});
}
}