ldapmanager/test/js/rangeslider.js

26 lines
1014 B
JavaScript
Raw Permalink Normal View History

2024-10-25 16:04:03 +00:00
document.addEventListener('DOMContentLoaded', function () {
const rangeInputs = document.querySelectorAll('input[type="range"]');
rangeInputs.forEach(rangeInput => {
// Get the maximum value
const max = rangeInput.max;
// Get the initial value; if not set, default to 0
2024-10-28 11:08:40 +00:00
const initialValue = rangeInput.value ? Number(rangeInput.value) : 50; // This may not work on all browsers. Firefox defaults this to 50
2024-10-25 16:04:03 +00:00
// console.log("initial val: " + initialValue);
const initialPercentage = (initialValue / max) * 100;
// Set the initial thumb position
rangeInput.style.setProperty('--value', `${initialPercentage}%`);
rangeInput.addEventListener('input', function () {
const value = rangeInput.value;
const percentage = (value / max) * 100;
// Update the width of the thumb based on the percentage
rangeInput.style.setProperty('--value', `${percentage}%`);
});
});
});