Zmieniłem (na "krótszy" z 1 sekundy na 0.3sekundy):
transition: border 1000ms ease;
na
transition: border 0.3s ease;
i js-a na:
const inputslider1 = document.getElementsByClassName("slider1")[0];
const inputslider1_min = inputslider1.getAttribute('min') * 1,
inputslider1_max = inputslider1.getAttribute('max') * 1;
changeColorSliderThumb();
inputslider1.addEventListener("mousemove", changeColorSliderThumb);
function changeColorSliderThumb() {
const percent = ((inputslider1.value - inputslider1_min) / (inputslider1_max - inputslider1_min)) * 100;
if (percent >= 0 && percent <= 33) {
inputslider1.classList.add("red");
inputslider1.classList.remove("orange");
}
if (percent >= 34 && percent <= 66) {
inputslider1.classList.add("orange");
inputslider1.classList.remove("green");
}
if (percent >= 67 && percent <= 100) {
inputslider1.classList.add("green");
}
}
cały kod do testowania na np: codepen
<input type="range" class="slider1" name="slider1" value="0" min="3" max="15" step="1">
.slider1 {
-webkit-appearance: none;
-moz-appearance: none;
position: absolute;
left: 50%;
top: 50%;
width: 100px; /* większy do testów, było 50px */
margin-top: 10px;
transform: translate(-50%, -50%);
}
input[name="slider1"]::-webkit-slider-runnable-track {
-webkit-appearance: none;
background: rgba(227, 59, 59);
background: -moz-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -moz-webkit-gradient(
left bottom,
right top,
color-stop(0%, rgb(227, 59, 59)),
color-stop(51%, rgb(230, 168, 87)),
color-stop(100%, rgb(93, 255, 53))
);
background: -webkit-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -o-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -ms-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3bade3 ', endColorstr='#ff357f ', GradientType=1 );
height: 2px;
}
input[name="slider1"]:focus {
outline: none;
}
input[name="slider1"]::-moz-slider-track {
-moz-appearance: none;
background: rgba(59, 173, 227, 1);
background: -moz-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -moz-webkit-gradient(
left bottom,
right top,
color-stop(0%, rgb(227, 59, 59)),
color-stop(51%, rgb(230, 168, 87)),
color-stop(100%, rgb(93, 255, 53))
);
background: -webkit-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -o-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: -ms-linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
background: linear-gradient(
45deg,
rgb(227, 59, 59) 0%,
rgba(230, 168, 87) 51%,
rgba(93, 255, 53) 100%
);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3bade3 ', endColorstr='#ff357f ', GradientType=1 );
height: 2px;
}
input[name="slider1"]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 2px solid;
border-radius: 50%;
height: 15px;
width: 15px;
max-width: 80px;
position: relative;
bottom: 6px;
background-color: #1d1c25;
cursor: -webkit-grab;
-webkit-transition: border 0.3s ease;
transition: border 0.3s ease;
}
input[name="slider1"]::-moz-slider-thumb {
-moz-appearance: none;
border: 2px solid;
border-radius: 50%;
height: 25px;
width: 25px;
max-width: 80px;
position: relative;
bottom: 11px;
background-color: #1d1c25;
-moz-transition: border 0.3s ease;
transition: border 0.3s ease;
}
.slider1.red::-webkit-slider-thumb {
border-color: rgb(227, 59, 59);
}
.slider1.orange::-webkit-slider-thumb {
border-color: rgb(230, 168, 87);
}
.slider1.green::-webkit-slider-thumb {
border-color: rgb(93, 255, 53);
}
.slider1.red::-moz-slider-thumb {
border-color: rgb(227, 59, 59);
}
.slider1.ogrange::-moz-slider-thumb {
border-color: rgb(230, 168, 87);
}
.slider1.green::-moz-slider-thumb {
border-color: rgb(93, 255, 53);
}
input[name="slider1"]::-webkit-slider-thumb:active {
cursor: grabbing;
}
input[name="slider1"]::-moz-slider-thumb:active {
cursor: grabbing;
}
const inputslider1 = document.getElementsByClassName("slider1")[0];
const inputslider1_min = inputslider1.getAttribute('min') * 1,
inputslider1_max = inputslider1.getAttribute('max') * 1;
changeColorSliderThumb();
inputslider1.addEventListener("mousemove", changeColorSliderThumb);
function changeColorSliderThumb() {
const percent = ((inputslider1.value - inputslider1_min) / (inputslider1_max - inputslider1_min)) * 100;
if (percent >= 0 && percent <= 33) {
inputslider1.classList.add("red");
inputslider1.classList.remove("orange");
}
if (percent >= 34 && percent <= 66) {
inputslider1.classList.add("orange");
inputslider1.classList.remove("green");
}
if (percent >= 67 && percent <= 100) {
inputslider1.classList.add("green");
}
}
function rangeSlide1(value) {
document.getElementById("rangeSlide1").innerHTML = value;
}