I am trying to make slider bars that will change the font-variation-settings of a variable font. I am trying to get these sliders to appear dynamically using PHP so that limits my options a tiny bit.
I've edited the post to remove the PHP.
I have the <h1> tag
<h1 class="variableFont" contenteditable="true" >Some Text Here</h1>
I'm using PHP that checks if it's a variable font and then checks which axis the font has then adds the appropriate sliders.
<p>Weight500</p>
<input type="range" min="0" max="1000" value="500" oninput="updatewght(this.value)">
<script>
function updatewght(newVal){
// Get the current value of font-variation-settings
var currentSettings = $('.variableFont').css('font-variation-settings');
// Split the current value into an array of variations
var currentVariations = currentSettings.split(',');
// Loop through the variations and change the current value
for (var i = 0; i < currentVariations.length; i++) {
if (currentVariations[i].indexOf('wght') >= 0) {
currentVariations[i] = "'wght' newVal"; // Change the axis value to whatever
}
}
// Join the variations back into a string and set the new value for font-variation-settings
var newSettings = currentVariations.join(',');
$('.variableFont').css('font-variation-settings', newSettings);
}
</script>
The sliders show up like they should, however when I move them it only ever returns
style="font-variation-settings: normal;"
I think the issue lies in where it splits the font-variation-settings and tries to jam it back together, but I can't figure out where I went wrong.