What is the method for altering the track color on a range slider?

Struggling to change the track color of a range slider using CSS in Chrome? Look no further, as I found a solution using jQuery (link). However, after implementing the solution, the expected output is not achieved.

jQuery:

$('.text-size-slider .slider').change(function () {
      var val = ($(this).val() - $(this).attr('min')) / ($(this).attr('max') - $(this).attr('min'));

      $(this).css('background-image',
                  '-webkit-gradient(linear, left top, right top, '
                  + 'color-stop(' + val + ', #94A14E), '
                  + 'color-stop(' + val + ', #C5C5C5)'
                  + ')'
                  );
  });

Plunker example: https://plnkr.co/edit/yMg8bKSrbam6RmtgdBl4?p=preview

Is there a way to achieve this without jQuery, using only pure JavaScript or AngularJS? Even with jQuery, the desired outcome is still not obtained as demonstrated in the Plunker.

Expected appearance: https://i.sstatic.net/NACFd.png

Any assistance would be highly appreciated. Please, someone assist me as I have tried several methods without success.

Answer №1

Your directive has been modified and can be viewed on this plunker:

"https://plnkr.co/edit/UPh0guqcXxO6ivSljh8R?p=preview"

Answer №2

Swap out style.css

body {

  color: blue;
  font-family: "Arial", "Arial", "Arial", sans-serif;
  font-weight: bold;
  margin: 10px;
}

header {

  background-color: yellow;  
  padding: 50px 30px;
}


h1 {
  font-size: 150%;
}

h3 {
  font-family: "Arial", "Arial", "Arial", "Arial", sans-serif;
  font-weight: bold;
}

p {
  font-size: 80%;
  font-weight: bold;
}

article {
  -webkit-column-count: 3;
  column-count: 3;
}

p {
  margin: 5px;
}

/**
 * Text Slider Directive - CSS  
 **/
.text-size-slider {
  line-height: 90%;
  font-size: 16px;
  position: absolute;
}

.text-size-slider .small-letter,.text-size-slider .big-letter
{
  font-weight: normal;
}

.text-size-slider .slider {
  -webkit-appearance: none;
  margin: 5px 10px;
}

.text-size-slider .slider:focus {
  outline: none;
}

.text-size-slider .slider::-webkit-slider-thumb {
  border: 1px solid black;
  cursor: grab;
  -webkit-appearance: none;
  background-color: rgba(50, 168, 82, 1);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  margin-top: -10px;
}
.text-size-slider .slider::-moz-range-thumb {
  border: 1px solid black;
  cursor: grab;
  -webkit-appearance: none;
  background-color: rgba(50, 168, 82, 1);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  margin-top: -10px;
}
.text-size-slider .slider::-ms-thumb {
  border: 1px solid black;
  cursor: pointer;
  -webkit-appearance: none;
  background-color: rgba(50, 168, 82, 1);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  margin-top: -10px;
}

.text-size-slider .slider::-webkit-slider-thumb::before {
 content:"GOOD";
 display:block;
 background:blue !important;
 height:25px;
 width:25px;
 position:absolute;
 top:-25px;
 left:-12px;
}
.text-size-slider .slider::-webkit-slider-thumb::after {
 content:"GOOD";
 display:block;
 background:orange !important;
 height:25px;
 width:25px;
 position:absolute;
 top:-25px;
 left:-12px;
}
.text-size-slider .slider::-moz-range-thumb::before {
 content:"GOOD";
 display:block;
 background:rgba(50, 168, 82, 1);
 height:25px;
 width:25px;
 position:absolute;
 top:-25px;
 left:-12px;
}

.pointer {
    vertical-align:bottom;
  height: 50px;
  width: 50px;
  border-radius:25px 25px  0 25px;
  background-color:rgba(50, 168, 82, 1);
  display:block;
  transform: rotate(90deg);
  position:absolute;
  top: -49px;
  margin-left:19px;

  color: white;

}

.pointer span {
  display: inline-block;
  transform: rotate(-90deg);
  margin-left:15px;
  margin-top: 19px;
  color: black;


}

.text-size-slider .slider::-webkit-slider-runnable-track {
  width: 110%;
  height: 4px;
  cursor: grab;

  border: 1px;
}
.text-size-slider .slider::-ms-track {
  width: 110%;
  height: 4px;
  cursor: pointer;
  background: purple;
  border: 1px;
}
.text-size-slider .slider::-moz-range-track {
  width: 110%;
  height: 4px;
  cursor: grab;
   background-color: #ccc;
  border: 1px;
}
.text-size-slider .slider::-moz-range-progress {
  background-color: rgba(50, 168, 82, 1); 
  height: 4px;
}
.text-size-slider .slider::-webkit-progress-value {
  background-color: pink;
}{
  background-color: rgba(50, 168, 82, 1); 
}
@-moz-document url-prefix() { .pointer { top: -50px; } }

 .text-size-slider .slider::-ms-fill-lower {
    background: purple;
    border-radius: 0;
  }

  .text-size-slider .slider::-ms-fill-upper {
    background: white;
    border-radius: 0;
  }
 .text-size-slider .slider{
    -webkit-appearance: none;
    -moz-apperance: none;
    height: 5px;
    background-image: -webkit-gradient( linear, right top, left top, color-stop(0.10, #ccc), color-stop(0.10, #ccc) );
}

.text-size-slider .slider::-webkit-slider-thumb {
    -webkit-appearance: none !important;
    background-color: #F1F1F1;
    border: 2px solid #B9B9B9;
    height: 25px;
    width: 25px;
}

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

Python Flask login screen not showing error message

Currently, I'm in the process of developing a login screen that incorporates Bootstrap and utilizes jQuery keyframes shaking effect. The backend functionality is managed by Flask. However, I seem to be encountering an issue where the error message "Wr ...

Tips for creating a clickable popover within a window that remains open but can be closed with an outside click

Is there a way to ensure that my popover window remains clickable inside its own area without closing, but automatically closes when clicked outside of the window? This is the code I am currently using, which is triggered by a button click: if (response. ...

What is the manual way to initiate the onclicksubmit event in jqgrid?

Is there a way to manually trigger the onclicksubmit event in jqgrid? If a certain condition is met, I need to programmatically call the submit event. See the code snippet below for reference. afterShowForm: function (formid) { if (condition) { ...

I discovered an issue in Handsontable while trying to copy and paste a numeric value in German format

For my upcoming project, I am looking to incorporate the Handsontable JavaScript grid framework. However, I have encountered a small bug that is hindering me from utilizing this library to its fullest potential. The task at hand involves displaying a tabl ...

Effortless AJAX/jQuery solution for displaying live file updates while copying

As I delve into the world of Ajax/jQuery, my current focus is on setting up a test environment for the following scenario: The server needs to recursively copy an entire folder from one location to another. The client should then display the list of copi ...

Is there a way to implement a function in Javascript or CSS where hovering over a button will cause a div to scroll either left or right

I am working on creating a unique photo gallery layout with a description block positioned below the images. My goal is to incorporate two arrow buttons, one on each side of the photos, that will trigger a scrolling effect when hovered over - shifting the ...

Transforming a string formatted as HH:MM into a Time Object

Within my Ionic AngularJS Project, there exists a variable named startingTime with a value of 08:30. My goal is to utilize an ng-repeat loop to generate a series of items with incremental times. The initial item will display 08:30, followed by subsequent ...

Hovering in Javascript

Imagine I have the following code snippet: <div class="class1"> ... random content </div> I want to use JavaScript so that when I hover over that div, a CSS attribute is added: background-color:#ffffe0; border:1px solid #bfbfbf; This is a ...

Trying to align a Material UI button to the right within a grid item

I'm attempting to right float the button below using material-ui, but I'm unsure of how to achieve this: <Grid item xs={2}> <Button variant="contained" color="secondary&quo ...

Display a hidden div only when a cookie is set during the initial visit

I'm currently facing an issue while trying to set multiple cookies based on the existence of a div using JavaScript. On the first visit, I want to display the div to the user if it exists, then set a cookie (named redCookie) that expires in 3 days. Up ...

How can jQuery-based Ajax/PHP be leveraged for synchronization effects?

I am currently in the process of creating a groceries application that allows for synchronization with other family members who are part of a 'family' group. When one member updates the grocery list on their device, the changes should automatical ...

Understanding how to translate the content of email confirmation and password reset pages in Parse Server

Is there a way to translate the Email Confirmation and Password Reset pages in my project using Parse server? I have searched everywhere for a solution but haven't found one yet. While I did come across information about email templates, I couldn&apos ...

What steps can be taken to avoid including empty tasks in React code?

Is there a way to prevent my application from adding empty tasks? Below is the code snippet for adding a new task to an array. How can I implement a condition to block the addition of empty tasks? This application follows Mozilla's guidelines for a R ...

Our system has picked up on the fact that your website is failing to verify reCAPTCHA solutions using Google reCAPTCHA V2

Error Message We have noticed that your website is not validating reCAPTCHA solutions. This validation is necessary for the correct functioning of reCAPTCHA on your site. Please refer to our developer site for further information. I have implemented the re ...

Minimize the entire project by compressing the .css, .js, and .html files

After recently incorporating Grunt into my workflow, I was thrilled with how it streamlined the process of minifying/concatenating .css files and minifying/uglify/concatenating .js files. With Grunt watch and express, I was able to automate compiling and ...

Discover the vertical measurement of a group with jquery

Among a group of child divs sharing the same class name, only one div will be visible depending on the user's selection while the others are hidden with the display: none; property. Is there a method to determine the height of the div currently in vi ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: https://i.sstatic.net/lw1vC.png C ...

Exploring the potential of npm init and harnessing the power of package.json

Recently, I started a fresh project using AngularJS. I cloned an existing project from the main branch master (master -> origin) (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caafb9b9afa4bea3aba6e7b8afaba9be8afae4f9e4fa"&g ...

Using HTML and JavaScript to choose relatives from the extended family: Uncles and Aunts

Looking for a better way to target elements in your HTML code? <div class="chunk" id=""> <div class="chunkContent"> <div class="textLeft" ></div> <div class="textRight" ></div> <div class= ...

Conflicting behavior between jQuery focus and blur functions and retrieving the 'variable' parameter via the $_GET method

There is a simple focus/blur functionality here. The default value shown in the 'Name of Venue' input field changes when the user clicks on it (focus) and then clicks away(blur). If there is no text entered, the default value reappears. Input fi ...