Looking for information on how to change the slider color depending upon what side of the dragable portion it is on, such as how the HTML5 video player slider does.
I've looked around for a bit and haven't found anything for pure JS solutions, only JQUERY, which I can't use. Any suggestions?
Depending on the design you can achieve this with pure CSS too:
input[type='range'] { -webkit-appearance: none; background-color: #ddd; height: 20px; overflow: hidden; width: 400px; } input[type='range']::-webkit-slider-runnable-track { -webkit-appearance: none; height: 20px; } input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; background: #333; border-radius: 50%; box-shadow: -210px 0 0 200px #666; cursor: pointer; height: 20px; width: 20px; border: 0; } input[type='range']::-moz-range-thumb { background: #333; border-radius: 50%; box-shadow: -1010px 0 0 1000px #666; cursor: pointer; height: 20px; width: 20px; border: 0; } input[type="range"]::-moz-range-track { background-color: #ddd; } input[type="range"]::-moz-range-progress { background-color: #666; height: 20px } input[type="range"]::-ms-fill-upper { background-color: #ddd; } input[type="range"]::-ms-fill-lower { background-color: #666; }
<input type="range"/>
width
and matching the box-shadow
of the slider-thumb to be more than the width
.
As the box-shadow
around the thumb is what is giving the appearance of different colours either side.
Also as this utilises overflow: hidden
on the input
you would not be able to have a bigger thumb than track.
Hence if the design is more specific I can also recommend noUISlider it doesn't use jQuery
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.