javascript - 如何更改滑块范围样式?
问题描述
我有一个输入来制作价格滑块范围。我只想改变它的风格,但没有任何效果。我错过了什么?
谢谢你的帮助!
<div class="panel-body">
<div class="container-fluid">
<input
id="range"
type="text"
data-slider-ticks="[0, 100, 200, 300, 400, 500]"
data-slider-ticks-snap-bounds="30"
data-slider-ticks-labels='["0€", "100€", "200€", "300€", "400€", "500€"]'
/>
</div>
</div>
{literal}
<style>
#range {
height: 5px;
color: grey;
}
</style>
<script>
$("#range").slider({
ticks: [0, 100, 200, 300, 400, 500],
ticks_labels: ["0€", "100€", "200€", "300€", "400€", "500€"],
ticks_snap_bounds: 30
});
</script>
{/literal}
解决方案
你忘了设置type="range"
。
关于如何设置范围滑块结帐的样式 https://www.w3schools.com/howto/howto_js_rangeslider.asp
总之,您需要设置-webkit-appearance: none;
然后设置背景属性,以便您的高度属性和其他样式可以应用。
<div class="panel-body">
<div class="container-fluid">
<input
id="range"
type="range"
data-slider-ticks="[0, 100, 200, 300, 400, 500]"
data-slider-ticks-snap-bounds="30"
data-slider-ticks-labels='["0€", "100€", "200€", "300€", "400€", "500€"]'
/>
</div>
</div>
{literal}
<style>
/* Styling the slider background */
#range {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: grey;
outline: none;
}
/* Styling the thumb */
#range::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: red;
cursor: pointer;
}
</style>
{/literal}
推荐阅读
- java - Add Java API to online server not localhost
- python-3.x - Lambifying Nested Parametric Integrals
- jquery - Column width changing by dragging the column edge using mouse and refreshing page leads to default width it is not updating the column width
- c# - Two or more server processes with one SQL Server DateTime flag. How to prevent overlap?
- julia - 无法预编译 JLD
- vuetify.js - 如何更改 Vuetify 按钮的文本颜色?
- javascript - 为什么这在 javascript 打印窗口对象中?
- java - HP Fortify 问题 - XML 外部实体注入
- ios - 了解配置文件和 Airwatch MDM
- c# - 如何使用 IEnumerable 作为导航属性而不是 IList