aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/controls.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-01-08 20:53:18 +1100
committerSam Potts <sam@potts.es>2018-01-08 20:53:18 +1100
commit8786377a755224ebc281488c5bea849639ae4f2a (patch)
tree31ceb00b871bae39696456b3005ba575f7f6340e /src/js/controls.js
parentf0322e8d94953ecc1373e31e34e31a24f7698079 (diff)
downloadplyr-8786377a755224ebc281488c5bea849639ae4f2a.tar.lz
plyr-8786377a755224ebc281488c5bea849639ae4f2a.tar.xz
plyr-8786377a755224ebc281488c5bea849639ae4f2a.zip
Use CSS custom property for webkit range fill
Diffstat (limited to 'src/js/controls.js')
-rw-r--r--src/js/controls.js26
1 files changed, 2 insertions, 24 deletions
diff --git a/src/js/controls.js b/src/js/controls.js
index 22ca30ad..936bee6b 100644
--- a/src/js/controls.js
+++ b/src/js/controls.js
@@ -26,30 +26,8 @@ const controls = {
return;
}
- // Inject the stylesheet if needed
- if (!utils.is.element(this.elements.styleSheet)) {
- this.elements.styleSheet = utils.createElement('style');
- this.elements.container.appendChild(this.elements.styleSheet);
- }
-
- const styleSheet = this.elements.styleSheet.sheet;
- const percentage = range.value / range.max * 100;
- const selector = `#${range.id}::-webkit-slider-runnable-track`;
- const styles = `{ background-image: linear-gradient(to right, currentColor ${percentage}%, transparent ${percentage}%) }`;
-
- // Find old rule if it exists
- const index = Array.from(styleSheet.rules).findIndex(rule => rule.selectorText === selector);
-
- // Remove old rule
- if (index !== -1) {
- styleSheet.deleteRule(index);
- }
-
- // Insert new one
- styleSheet.insertRule([
- selector,
- styles,
- ].join(' '));
+ // Set CSS custom property
+ range.style.setProperty('--value', `${range.value / range.max * 100}%`);
},
// Get icon URL