最近在进行开发的时候,用到了滑动栏,后来发现,h5自带的原生标签也可以实现滑动栏的效果,另外就是使用 noUislider也可以实现功能,今天主要记录一下h5原生的标签。
首先可以直接使用h5的input标签,把type改为 type="range"即可。
<input type="range">
在这里主要介绍几种属性
value 可以设置默认值 value=“0”
min 滑动栏的最小值 min=“0”
max 滑动栏的最大值 max=“10”
step 每次拉动递增或递减的值 step=“1”
使用下列方法可以进行实时监听
<input type="range" value="0" min="0" max="200" step="1">
<div class="text"></div>
<script>
$('input[type=range]').on('input propertychange', function() {
var val = $(this).val();
$(".text").html(val)
})
</script>
当然我们也可以对默认的样式进行改变
<style>
input[type=range]:focus {
display: none;
}
input[type=range] {
-webkit-appearance: none;
width: 500px;
border-radius: 10px;
/*这个属性设置使填充进度条时的图形为圆角*/
}
input[type=range]::-webkit-slider-runnable-track {
height: 20px;
border-radius: 10px;
/*将轨道设为圆角的*/
/* box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; */
border: solid 1px red;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 30px;
width: 120px;
margin-top: -5px;
/*使滑块超出轨道部分的偏移量相等*/
background: #ffffff;
/* border-radius: 50%; */
/*外观设置为圆形*/
border: solid 0.125em rgba(205, 224, 230, 0.5);
/*设置边框*/
/* box-shadow: 0 .125em .125em #3b4547; */
/*添加底部阴影*/
}
</style>
效果图就是这样的
当然也可以通过改造做成你想要的样子。