Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active November 2, 2020 07:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daliborgogic/82c33d468401580ae3913f24910c0683 to your computer and use it in GitHub Desktop.
Save daliborgogic/82c33d468401580ae3913f24910c0683 to your computer and use it in GitHub Desktop.
Variable Fonts Vue.js
<template>
<div id="app" :style="cssVariables">
<label>wdth</label>
<input type="range" min="10" max="700" v-model="wght">
<label>wght</label>
<input type="range" min="10" max="100" v-model="wdth">
<span>The quick brown fox jumps over the lazy dog</span>
</div>
</template>
<script>
export default {
data () {
return {
wdth: 10,
wght: 10
}
},
computed: {
cssVariables () {
return {
'--wdth': this.wdth,
'--wght': this.wght
}
}
}
}
</script>
<style>
@supports (font-variation-settings: 'wdth' 200) {
body { background-color: rgb(0, 255, 0, 0.12); }
@font-face {
font-family: 'AmstelvarAlpha';
src: url('./assets/AmstelvarAlpha-VF.ttf');
}
span {
font-family: AmstelvarAlpha;
font-size: 32px;
font-variation-settings: 'wdth' var(--wdth), 'wght' var(--wght);
}
}
@supports not (font-variation-settings: 'wdth' 200) {
body { background-color: rgb(255, 0, 0, 0.12); }
/* Add fallback font */
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment