admin管理员组

文章数量:1325080

I'm trying to create a seek bar for the video and I want to show black color on the seek bar representing the amount of video which has been downloaded. How can I assign an additional color on the seek bar representing the amount of video downloaded?

I think I didn't explain my question properly. I want a color (e.g. silver) which shows the amount of video which has been downloaded for playing. Silver color on the seek bar can be found in the default html5 video and YouTube video player. (Image provided below)

var player = document.querySelector("video"),
    seek_bar = document.querySelector("input"),
    _console = document.querySelector("div");

player.ontimeupdate = function() {
  seek_bar.value = this.currentTime.toString().split(".")[0];
}
player.addEventListener('progress', function() {
  try {
    _console.innerHTML = "Downloaded Upto: " + this.buffered.end(0).toString().split(".")[0];
  } catch(e) {}
});
video {
  width: 90%;
  height: 75%;
}
input[type="range"] {
  width: 90%;
  height: 10px;
  background: rgb(110, 170, 250);
  border: 1px solid rgb(15, 15, 15);
  border-radius: 50px;
  -webkit-appearance: none !important;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none !important;
  background: rgb(15, 15, 15);
  height: 20px;
  width: 20px;
  cursor: pointer;
  border-radius: 100%;
}
<html>
<head>
  <title></title>
</head>
<body>
  <video src=".mp4" controls></video>
  <input type="range" min="0" value="0" max="634"/>
  <div></div>
</body>
</html>

I'm trying to create a seek bar for the video and I want to show black color on the seek bar representing the amount of video which has been downloaded. How can I assign an additional color on the seek bar representing the amount of video downloaded?

I think I didn't explain my question properly. I want a color (e.g. silver) which shows the amount of video which has been downloaded for playing. Silver color on the seek bar can be found in the default html5 video and YouTube video player. (Image provided below)

var player = document.querySelector("video"),
    seek_bar = document.querySelector("input"),
    _console = document.querySelector("div");

player.ontimeupdate = function() {
  seek_bar.value = this.currentTime.toString().split(".")[0];
}
player.addEventListener('progress', function() {
  try {
    _console.innerHTML = "Downloaded Upto: " + this.buffered.end(0).toString().split(".")[0];
  } catch(e) {}
});
video {
  width: 90%;
  height: 75%;
}
input[type="range"] {
  width: 90%;
  height: 10px;
  background: rgb(110, 170, 250);
  border: 1px solid rgb(15, 15, 15);
  border-radius: 50px;
  -webkit-appearance: none !important;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none !important;
  background: rgb(15, 15, 15);
  height: 20px;
  width: 20px;
  cursor: pointer;
  border-radius: 100%;
}
<html>
<head>
  <title></title>
</head>
<body>
  <video src="https://dash.akamaized/akamai/bbb/bbb_1920x1080_60fps_12000k.mp4" controls></video>
  <input type="range" min="0" value="0" max="634"/>
  <div></div>
</body>
</html>

SILVER (THE OTHER COLOR) ON THE SEEK_BAR:

Share edited Apr 24, 2019 at 1:49 aman asked Apr 23, 2019 at 9:15 amanaman 4012 gold badges24 silver badges53 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Here is an example of something similar I did a couple of years ago: https://jsfiddle/remisture/esyvws3d/

$(window).on("load resize", function() {
  // Get the current width of the slider
  var sliderWidth = $('[type=range]').width();

  // Remove previously created style elements
  $('.custom-style-element-related-to-range').remove();

  // Add our updated styling
  $('<style class="custom-style-element-related-to-range">input[type="range"]::-webkit-slider-thumb { box-shadow: -' + sliderWidth + 'px 0 0 ' + sliderWidth + 'px;}<style/>').appendTo('head');
});
.container {
  margin: 0 auto;
  width: 500px;
}

input[type='range'] {
  width: 100%;
}

/*Chrome*/

@media screen and (-webkit-min-device-pixel-ratio:0) {
  input[type='range'] {
    overflow: hidden;
    -webkit-appearance: none;
    background-color: #9a905d;
  }
  input[type='range']::-webkit-slider-runnable-track {
    height: 10px;
    -webkit-appearance: none;
    color: #13bba4;
    margin-top: -1px;
  }
  input[type='range']::-webkit-slider-thumb {
    width: 10px;
    -webkit-appearance: none;
    height: 10px;
    cursor: ew-resize;
    background: #434343;
    color: #43e5f7;
  }
}


/** FF*/

input[type="range"]::-moz-range-progress {
  background-color: #43e5f7;
}

input[type="range"]::-moz-range-track {
  background-color: #9a905d;
}


/* IE*/

input[type="range"]::-ms-fill-lower {
  background-color: #43e5f7;
}

input[type="range"]::-ms-fill-upper {
  background-color: #9a905d;
}
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="container">
  <input type="range">
</div>

For this I would use the HTML progress element.

Here is how you would style it if you wanted the meter showing the amount of video downloaded to have black color.

progress
  -webkit-appearance: none /* Important, otherwise your styles won't have effect */

progress::-webkit-progress-value
  background: black

Here's a live Codepen demo

本文标签: javascriptApply different color on two parts of input rangeStack Overflow