-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpriceFilterScript.js
More file actions
60 lines (58 loc) · 2.4 KB
/
priceFilterScript.js
File metadata and controls
60 lines (58 loc) · 2.4 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
// JavaScript for the price range slider
// Get the range input and price input
const rangeInput = document.querySelectorAll('.range-input input');
priceInput = document.querySelectorAll('.price-input-container input');
// Get the progress bar
progress = document.querySelector(".slider .price");
// Set the price gap
let priceGap = 1000;
priceInput.forEach(input =>{
// Add event listener to the input
input.addEventListener("input", e =>{
//get the two input values of the range input
let minVal = parseInt(priceInput[0].value);
maxVal = parseInt(priceInput[1].value);
//get the two values of the range input
if((maxVal - minVal >= priceGap) && max <= 5000 && min >= 0){
// Set the value of the range input
if (e.target.className === "min-input")
{
// Set the value of the range input
rangeInput[0].value = minVal;
progress.style.left = (minVal / rangeInput[0].max) * 100 + "%";
}
else{
rangeInput[1].value = maxVal;
progress.style.right = 100 - (maxVal / rangeInput[1].max) * 100 + "%";
}
}
})
})
// Add event listener to the range input
rangeInput.forEach(input =>{
// Add event listener to the input
input.addEventListener("input", e =>{
//get the two values of the range input
let minVal = parseInt(rangeInput[0].value);
maxVal = parseInt(rangeInput[1].value);
//get the two values of the price input
if(maxVal - minVal < priceGap){
// Set the value of the price input
if (e.target.className === "range-min")
{
// Set the value of the price input
rangeInput[0].value = maxVal - priceGap;
}
else{
rangeInput[1].value = minVal + priceGap;
}
}
else{
// Set the value of the price input
priceInput[0].value = minVal;
priceInput[1].value = maxVal;
progress.style.left = (minVal / rangeInput[0].max) * 100 + "%";
progress.style.right = 100 - (maxVal / rangeInput[1].max) * 100 + "%";
}
})
})