Slider question change of color change of selected part.
I need to customize the Slider’s progress line to display a different color than the default. For instance, if a respondent selects 25% on a 100% slider, the first 25% of the slider should be a different color from the rest of the bar. Also if we can add interval ticks that will be helpful as well. Example Shown in SS attached.
Any assistance or recommendations would be greatly appreciated.
Page 1 / 1
@harendra.kumar,
I have a JS function that adds slider ticks that you can contact me about via private message.
To add colors to the sliders, you’ll first need to switch the Slider Type from Sliders to Bars. Then you can set the background image to linear-gradient.
Hi @TomG
I believe you're charging for the code you have, and I'm not in favour of that. This community is meant for knowledge sharing, and it should stay that way.
@harendra.kumar
You can follow @TomG code for the slider ticks Switch the Slider Type from Sliders to Bars. Add this code to the question JavaScript, change the color code if you like
function updateSliderColor(value) { if (value < 25) { sliderBar.style.backgroundColor = 'red'; console.log("Slider color changed to red at value: " + value); } else if (value < 50) { sliderBar.style.backgroundColor = 'yellow'; console.log("Slider color changed to yellow at value: " + value); } else if (value < 75) { sliderBar.style.backgroundColor = 'green'; console.log("Slider color changed to green at value: " + value); } else { sliderBar.style.backgroundColor = 'blue'; console.log("Slider color changed to blue at value: " + value); } }
function updateSlider() { let currentValue = parseInt(sliderInput.value, 10); if (!isNaN(currentValue)) { console.log(`updateSlider() called. Current value: ${currentValue}`); updateSliderColor(currentValue); } else { console.error('Unable to retrieve slider value'); } }
Thank you for sharing this, just checking if this code will change the colour of entire bar or only for the selected part of the bar. The requirement is to only change the colour of selected part of the bar as shown in SS attached.
Hi @Nam Nguyen
Thank you for sharing this, just checking if this code will change the colour of entire bar or only for the selected part of the bar. The requirement is to only change the colour of selected part of the bar as shown in SS attached.
@harendra.kumar Only the filled part
Hi @TomG
I believe you're charging for the code you have, and I'm not in favour of that. This community is meant for knowledge sharing, and it should stay that way.
I can understand how someone who only gets solutions and never contributes any would feel that way.
@TomG It could be that the person asking for help is a beginner and lacks the expertise to contribute, but does that justify someone using an open forum to promote and run their business? I have seen you several time selling your code here.
Thank you @Nam Nguyen for sharing the code. I am also found a way to add ticks. Below is the Code if this can help anyone. Though it is not a dynamic code but it will do the work.
@TomG It could be that the person asking for help is a beginner and lacks the expertise to contribute, but does that justify someone using an open forum to promote and run their business? I have seen you several time selling your code here.
I give people an option. When they take their own time into account, many people find it makes more sense for both economic and quality reasons to purchase a solution that works better than anything they could create themselves.