How do I change the color on my noUiSliders depending on the value it currently is at?

marcamillion

So I created some custom color classes for my sliders and it works well...this is how it looks:

colored-sliders

All I simply did was created the following classes:

.red .noUi-connect {
  background: #c0392b;
}

.orange .noUi-connect {
  background: #2980b9;
}

.green .noUi-connect {
  background: #27ae60;
}

And applied them to my divs like so:

<div id="slider-speed" class="slider red"></div>
<div id="slider-speed" class="slider orange"></div>
<div id="slider-speed" class="slider green"></div>

However, what I want to do is whenever the user moves the slider left or right, the color of the slider changes based on the value.

So 1 - 3 = red, 4 - 6 = orange, 7 - 10 = green.

How do I do that?

hackerrdave

You could try using the event callback for "update" like this:

slider.noUiSlider.on('update', function(values, handle){
  updateColorClass(document.getElementById('slider-speed'), values[handle]);
});

function updateColorClass(element, value) {
  var color;
  if (value < 4) { 
    color = 'red';
  } else if (value < 7) { 
    color = 'orange';
  } else {
    color = 'green';
  }

  element.classList.remove("red", "orange", "green");
  element.classList.add(color);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I set a default color in my box and let the color change depending on input?

In my Blazor server side app I want to change the text color in a razor page, depending on a variable value in the related razor.cs file. How to do?

How can I change the color in javascript depending of object value

How do I set a color for each point in a graph depending on a value

How To Change Color Of <td> element depending on value

How can I change color depending on health?

How to change color lines to gradient color depending on the value

How can I change td background color depending on value in a table using JavaScript / jQuery?

How do I change the background color of a cell depending on the date in Google Sheets?

Change row color depending on $value

how do I change my header background color?

Using dircolors, how do I change the color of my subversion folders

How do I change color of a certain part of my textview?

How do I change the color of my background smoothly?

How do I change the color of my DIV when checkbox is checked?

How do I change color and font of my bootstrap nav tabs

How do I change my button color and text in Ionic Framework?

How do i change the background color of my website with HTML

How do I change the innerHTML of a date input to make the value match the currently user-entered value?

How to change the value of the input field of my form depending on the page I am in

How can I make my code change the worksheet it is referencing depending on the value in a combobox?

How do I change color's hue, saturation, or value in Flutter?

How do I change the color of an infobox in shinydashboard based on a string, not a value?

how to change the color of the graph depending on the value of the column in R

How to change background color in paragraph depending on the value in reactjs

How can I change body background color depending on active slide?

How do I change information in textboxes depending on patient weight value dynamically?

How do I pass a specific string to my partial depending on the value of another variable also being passed to it?

How do I get the currently selected pencil kit color?