-
Notifications
You must be signed in to change notification settings - Fork 0
/
slide.html
112 lines (97 loc) · 2.33 KB
/
slide.html
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
<!DOCTYPE html>
<html>
<head>
<title>Slider y cuenta</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
h1 {
margin-top: 0;
}
p {
margin-bottom: 20px;
}
#slider {
-webkit-appearance: none;
appearance: none;
width: 80%;
max-width: 300px;
height: 10px;
background: #ccc;
outline: none;
border-radius: 5px;
margin: 0;
padding: 0;
cursor: pointer;
transition: background 0.2s;
}
#slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 40px;
height: 40px;
/*background: url(reel.svg) center/contain no-repeat;*/
border-radius: 50%;
cursor: pointer;
}
#slider::-moz-range-thumb {
width: 40px;
height: 40px;
/*background: url(reel.svg) center/contain no-repeat;*/
border: none;
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<p>Cuenta: <span id="cuenta">10</span> metros</p>
<input type="range" id="slider" min="-10" max="10" value="0">
<script>
var cuenta = 10;
var slider = document.getElementById("slider");
var cuentaElement = document.getElementById("cuenta");
var sliderValue = 0;
var isHolding = false;
slider.addEventListener("input", function() {
sliderValue = parseInt(slider.value);
});
slider.addEventListener("mousedown", startDrag);
slider.addEventListener("touchstart", startDrag);
slider.addEventListener("mouseup", stopDrag);
slider.addEventListener("touchend", stopDrag);
setInterval(function() {
if (isHolding) {
cuenta += sliderValue^2 / 5;
cuenta = cuenta <= 0 ? 0 : cuenta;
cuentaElement.textContent = cuenta;
}
}, 500);
window.addEventListener("mouseup", function() {
if (!isHolding) {
resetSlider();
}
});
function startDrag() {
isHolding = true;
}
function stopDrag() {
isHolding = false;
sliderValue = 0;
resetSlider();
}
function resetSlider() {
slider.value = 0;
sliderValue = 0;
}
</script>
</body>
</html>