<main class="container">
<div>
<h1 class="demo-text">Hello</h1>
</div>
<div class="controls">
<!-- Weight Controls -->
<div class="slider-container">
<input type="range" min="100" max="900" value="500" class="slider" id="text-weight" name="text-weight" data-index="0">
<div class="slider-controls">
<label for="text-weight" class="slider-label">
Weight: <span class="output" data-index="0"></span>
</label>
<button class="button" data-index="0">
Reset
</button>
</div>
</div>
<!-- Width Controls -->
<div class="slider-container">
<input type="range" min="75" max="100" value="100" class="slider" id="text-width" name="text-width" data-index="1">
<div class="slider-controls">
<label for="text-width" class="slider-label">
Width: <span class="output" data-index="1"></span>
</label>
<button class="button" data-index="1">
Reset
</button>
</div>
</div>
<!-- Slant Controls -->
<div class="slider-container">
<input type="range" min="0" max="12" value="0" class="slider" id="text-slant" name="text-slant" data-index="2">
<div class="slider-controls">
<label for="text-slant" class="slider-label">
Slant: <span class="output" data-index="2"></span>
</label>
<button class="button" data-index="2">
Reset
</button>
</div>
</div>
</div>
</main>
/* Load the variable font */
@font-face {
font-family: 'Roboto VF';
src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/Roboto-VF.woff2') format('woff2-variations');
font-stretch: 75% 100%;
font-style: oblique 0deg 12deg;
font-weight: 100 900;
}
:root {
--text-weight: 500;
--text-width: 100;
--text-slant: 0;
}
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
margin: 0;
}
.container {
font-family: "Roboto VF", "Roboto", sans-serif;
margin: 0 auto;
max-width: 60rem;
padding: 3rem;
text-align: center;
}
.demo-text {
font-size: 5rem;
font-stretch: var(--text-width);
font-style: oblique var(--text-slant);
font-weight: var(--text-weight);
font-variation-settings: "wght" var(--text-weight), "wdth" var(--text-width), "slnt" var(--text-slant);
margin: 0;
}
.controls {
margin-top: 3rem;
}
.slider-container:not(:first-child) {
margin-top: 3rem;
}
.slider-controls {
display: flex;
justify-content: space-between;
margin-top: 1rem;
}
.slider-label {
font-size: 1.25rem;
font-style: normal;
font-variation-settings: "slnt" var(--text-slant);
font-weight: 650;
}
.output {
font-style: normal;
font-variation-settings: "slnt" var(--text-slant);
font-weight: 400;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 1rem;
border-radius: .25rem;
background: #dee7ec;
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 1.75rem;
height: 1.75rem;
border-radius: 50%;
background: #456bd9;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 1.75rem;
height: 1.75rem;
border-radius: 50%;
background: #456bd9;
cursor: pointer;
}
.slider::-webkit-slider-thumb:active {
cursor: -webkit-grabbing;
}
.slider::-moz-range-thumb:active {
cursor: -moz-grabbing;
}
.button {
background: #fff;
border: 3px solid #dee7ec;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
font-weight: 400;
opacity: 1;
padding: .25rem .75rem;
transition: background ease-in .2s;
}
.button:hover,
.button:focus {
background: #eaf0f3;
}
const container = document.querySelector(".container");
const sliders = document.querySelectorAll(".slider");
const sliderValues = document.querySelectorAll(".output");
const buttons = document.querySelectorAll(".button");
// Display property values
for (let i = 0; i < sliders.length; i++) {
sliderValues[i].innerHTML = sliders[i].value;
}
// Update text property and displayed property value for each slider
sliders.forEach(slider => {
const sliderIndex = slider.getAttribute("data-index");
const output = document.querySelector(`.output[data-index="${sliderIndex}"]`);
slider.oninput = function() {
container.style.setProperty(`--${this.id}`, this.value);
output.innerHTML = this.value;
};
});
// Reset text property and update display property value for each slider
buttons.forEach(button => {
const buttonIndex = button.getAttribute("data-index");
const resetOutput = document.querySelector(
`.output[data-index="${buttonIndex}"]`
);
const resetSlider = document.querySelector(
`.slider[data-index="${buttonIndex}"]`
);
button.onclick = function() {
container.style.removeProperty(`--${resetSlider.id}`);
resetOutput.innerHTML = resetSlider.defaultValue;
resetSlider.value = resetSlider.defaultValue;
console.log(resetSlider.defaultValue);
};
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.