XStack

Deep into details

0%

拖动选择控件自定义样式

为什么要用input[type=range], 而不是div+touch事件模拟?#

  • 性能考量(拖拽的性能要比模拟的好一些)
  • 工作量考虑(改改样式就好了)
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
<!DOCTYPE html>
<html>
<head>
<style>
body{padding-top: 30px;}
input[type=range]{
-webkit-appearance: none;
outline: none;
width: 478px;
zoom: 0.5;
}
input[type=range]::-webkit-slider-runnable-track {
-webkit-appearance: none;
height: 4px;
background: #dddddd;
background: -webkit-linear-gradient(left, #ffa42f 0%, #ffa42f 30%, #dddddd 30%)
}
::-webkit-slider-thumb {
-webkit-appearance: none;
border-radius: 20px;
height: 20px;
width: 20px;
border-radius: 20px;
background: #ffa42f;
box-shadow: 0 0 0 10px rgba(255,164,47,0.5);
margin-top: -8px;
}
</style>
</head>
<body>
<input type="range" value="30"/>
</body>
</html>