-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslider.html
More file actions
132 lines (121 loc) · 2.96 KB
/
slider.html
File metadata and controls
132 lines (121 loc) · 2.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Range Slider</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Readex+Pro:wght@400;700&display=swap"
rel="stylesheet"
/>
<style>
body {
font-family: "Readex Pro";
height: calc(100vh - 100px);
margin: 50px;
padding: 0;
}
@media only screen and (max-width: 1350px) {
.slidecontainer {
width: calc(100% - 140px) !important;
}
body {
margin: 20px;
}
}
#percentage {
font-size: 30px;
}
.slidecontainer {
width: 30%;
text-align: center;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
padding: 50px;
border-radius: 10px;
}
.slider {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
-webkit-transition: 0.2s;
transition: opacity 0.2s ease;
border-radius: 7px;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 40px;
height: 40px;
background: #0069ff;
cursor: pointer;
border-radius: 50%;
}
h3 {
margin: 0;
}
#risk-rating {
border: 2px solid;
display: inline-block;
padding: 10px;
border-radius: 10px;
}
.back {
color: rgba(0, 0, 0, 0.4);
text-decoration: none;
font-size: 20px;
}
</style>
</head>
<body>
<a href="index.html" class="back">back</a>
<div class="slidecontainer">
<h3 id="percentage"></h3>
<p id="risk-rating"></p>
<input
type="range"
min="1"
max="100"
value="40"
class="slider"
id="range"
/>
</div>
<script>
let slider = document.getElementById("range")
let percentage = document.getElementById("percentage")
let risk_rating = document.getElementById("risk-rating")
percentage.innerHTML = slider.value + "%" // Display the default slider value
function updateRiskRating() {
if (slider.value < 25) {
risk_rating.textContent = "Low risk"
risk_rating.style.color = "#339900"
} else if (slider.value < 50) {
risk_rating.textContent = "Moderate risk"
risk_rating.style.color = "#ffcc00"
} else if (slider.value < 75) {
risk_rating.textContent = "High risk"
risk_rating.style.color = "#ff9966"
} else {
risk_rating.textContent = "Very high risk"
risk_rating.style.color = "#cc3300"
}
}
updateRiskRating()
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function () {
percentage.innerHTML = this.value + "%"
updateRiskRating()
}
</script>
</body>
</html>