Is it possible to customize the colors of the bar on the jQuery Slider?

Welcome to my jQuery Slider demonstration!

JSFIDDLE

Check out my JS Fiddle Example

Coloured Bar

 $('.ui-widget-content').css('background','green');

I have successfully colored the bar green using the code above, but now I want to take it a step further.

What I am looking to achieve is having different colors on the bar based on specific value ranges. For instance, I want the bar to be red for values between 0 and 30, orange between 30 and 70, and green between 70 and 100.

This way, as the slider moves across the bar, it transitions through red, orange, and green sections.

Do you think this customization is possible?

The linear gradient solution works perfectly for me, but unfortunately, my client is still using IE8 which does not support it.

Answer №1

To achieve the desired effect, you can incorporate a linear gradient in your background using the following code snippet:

$('.ui-widget-content').css('background','linear-gradient(to right, red 30%, orange 30%, orange 70%, green 70%, green 100%)');

If you are curious about browser support for linear gradients, you can check it out here: http://caniuse.com/#feat=css-gradients

For a live demonstration, feel free to view this example on jsFiddle: http://jsfiddle.net/teawd5dw/

Answer №2

@Marcelo's solution was a more refined and suitable answer for my needs. Unfortunately, it didn't work well in IE8, which was the client's preferred browser. I had to come up with an alternative approach.

I ended up using the stop function along with simple if statements. It may not be the ideal solution, but it gets the job done.

$("#slider").slider(
{
            value:50,
            min: 0,
            max: 100,
            step: 10,
            slide: function( event, ui ) {
                $( "#slider-value" ).html( ui.value );
            },
            stop: function( event, ui ) {
                var num = ui.value;
                if(num <= 30){
                $('.ui-widget-content').css('background','red');
                }
                if(num > 30 || num < 70){
                $('.ui-widget-content').css('background','orange');
                }
                if(num >= 70){
                $('.ui-widget-content').css('background','green');
                }
            }
}
);

$( "#slider-value" ).html(  $('#slider').slider('value') );

JSFIDDLE

Check out the JS Fiddle Example here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Adobe XD, I can create shapes that appear blurry with crisp edges, but in real life

While working on my app design, I decided to use a shape blur filter in Adobe XD to create an app-bar-bottom, as shown below. Now I'm wondering if this design can be implemented for web or mobile development. I know that when using a blur filter in CS ...

Activate hover effect on desktop screen (excluding tablets and phones) by utilizing media queries

Applying hover state styling to a div can be done like this: div { &:hover { color: red !important; border: 3px solid red !important; } } To exclude iPads and other tablets from this CSS style, you can util ...

Retrieving JSON data with Typescript

https://i.sstatic.net/i5vFM.jpg I recently received some data from a request, expecting to return a JSON object that I can utilize in HTML. However, upon running console.log(this.data); I noticed that there are 20 elements in the articles array, but it ...

When zooming in or out on a mobile device, an unusual white line appears

Encountering a strange white gap on mobile devices when zooming in or out. This issue seems to be related to the use of background-color on sections. Strangely, the problem only occurs on mobile devices while zooming in, but does not appear on normal deskt ...

Angular: Consistently losing focus on TextArea whenever its model is updated

Currently, I am using the Socket.io library to broadcast changes to all subscribers when data in a textarea is updated. However, I am facing an issue where the textarea loses its focus when it is being updated while in a focus state. My goal is to only upd ...

Changing the color along with the background color transition

I'm looking to create a website with a blue background that transitions from a light shade of blue at the top to a darker shade at the bottom. Is there a way to achieve this effect using CSS or jQuery? Most examples I've found involve hover effec ...

When using angular's ngHide directive on a button, it will still occupy space in the

At the bottom of this HTML file, there are 3 buttons displayed. The first image illustrates the layout of the 3 buttons. The second image demonstrates what happens when the middle button in the footer is commented out. The third image shows the situat ...

Why isn't my li:hover responding the way it should?

Check out this Fiddle When the mouse hovers over the element, an opaque "cloud" appears and I want to completely hide the underline that is normally displayed. The underline is created by using a border-bottom on the parent div. .element_style{ width ...

Can the bottom border on an input textfield be removed specifically under the new character?

This is the new visual design I received: https://i.stack.imgur.com/kiQGe.png The label CLG is represented as a label, with the line being an input type=tel. Disregard the purple overlay... The designer has requested that I remove the border when a user ...

Having trouble getting the Basic Drag and Drop JavaScript code to function correctly?

Apologies, my English skills are not the best! I attempted to implement a basic JavaScript, HTML, and CSS drag-and-drop feature but it doesn't seem to be working correctly. Can someone please take a look at the website to see what is going wrong? ...

What is the best way to position my image on the right side of the page?

Trying to position an image on the right side, but facing issues with overlapping social media icons when using the pull-right class in bootstrap. Desired image layout:https://i.sstatic.net/tyfjW.png UPDATE: For reference, here is a link to the header i ...

Launching another browser tab quietly

My goal is to open a new tab in the background, similar to how it works on vouchercodes where you click a link and return to the previous tab. I have read that this may not be possible with Javascript, but I am using JQuery mobile. Here's what I&apos ...

Unable to Toggle Bootstrap 5 Dropdown

Take a look at my code below. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewpor ...

Eliminating duplicate CSS properties from multiple CSS files can help streamline your stylesheets

I am dealing with a situation where I have two CSS files containing redundant CSS properties. For example, in foo.css: #test { border: 0; font-size: 16px; } In bar.css: #test { border: 0; font-size: 32px; width: auto; } My goal is ...

Changing the name of a CSS file on the live server

I was recently browsing a website and noticed that they had given their CSS file a really long name. The website in question is It seems like they are using Twitter Bootstrap as their web UI framework, so I'm curious as to why they would choose such ...

Sliding background in a multi-column accordion

I've hit a roadblock with this project. I'm working on setting up a FAQ section that needs to display its items in two columns on desktop, each with a drop shadow effect using Bootstrap 4. I've experimented with Flexbox and CSS columns with ...

Requesting Json data via Ajax in Laravel 4 using Jquery

I am working on a jQuery AJAX request: var containerSettings = {}; containerSettings.font_family = $j("#supercontainer").css("font-family"); var containerSettingsJson = JSON.stringify(containerSettings); var BASE = "<?php echo Request::Root( ...

Refreshing a webpage is not necessary when using a JQuery form within a div

I need help with some code I have. In my index.html file, there is a div: <div id="logindiv"> <?php require_once('login.php'); ?> </div> This div is utilized with jQuery: <script type="text/javascript"> $(document ...

Altering the flex-direction causes my divs to vanish into thin air

Just starting out with css, trying to get some practice. I'm attempting to position two divs on opposite sides of a parent div. Switching flex-direction from 'column' to 'row' causes the divs to disappear. #assignments-wrapp ...

deleting the current product information during an ajax request

After executing the query provided below, I have $product_list in this code. However, I want to use ajax so that when I click on the button link1, $product_list gets emptied. How can I clear the content within products_list using an ajax call triggered by ...