最终效果
遇到的问题:
1、无法直接修改 input 进度条进度条颜色,解决办法使用css3背景渐变解决
css: 需要注意加上-webkit-appearance: none 否则无效
/*滑动条背景*/
input[type="range"] {
-webkit-appearance: none;
width: 522px;
height: 24px;
background: linear-gradient(90deg, #1C2D4B 0%, #292F3A 100%);
border-radius: 12px;
box-shadow: 0px 0px 8px 0px rgba(68,119,255,1);
}
input[type="range"]::-ms-fill-lower {
-webkit-appearance: none;
background: #f00;
}
/*滑动条操作按钮样式*/
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 6px;
height: 24px;
background: #4477FF;
box-shadow: 0px 0px 6px 0px rgba(68,119,255,1);
}
完整案例:
<template>
<div style="margin: 50px;">
<input
v-model="input"
max="1000"
:style="{'background': `linear-gradient(to right, rgba(68, 119, 255, 0.2) ${getPercent(input, 1000)}%, #252E3F ${ getPercent(input, 1000)}% `}"
type="range">
<span class="c_fff">{{input}}</span>
</div>
</template>
<script>
export default {
data () {
return {
input: 0
}
},
mounted () {
},
methods: {
getPercent (num, total) {
num = parseFloat(num)
total = parseFloat(total)
if (isNaN(num) || isNaN(total)) {
return 0
}
return total <= 0 ? 0 : (Math.round(num / total * 10000) / 100.00)
},
}
}
</script>
<style lang="less">
/*滑动条背景*/
input[type="range"] {
-webkit-appearance: none;
width: 522px;
height: 24px;
background: linear-gradient(90deg, #1C2D4B 0%, #292F3A 100%);
border-radius: 12px;
box-shadow: 0px 0px 8px 0px rgba(68,119,255,1);
}
input[type="range"]::-ms-fill-lower {
-webkit-appearance: none;
background: #f00;
}
/*滑动条操作按钮样式*/
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 6px;
height: 24px;
background: #4477FF;
box-shadow: 0px 0px 6px 0px rgba(68,119,255,1);
}
</style>