I'm trying to use a variable font whose weight responds to mouse movement. I grabbed some code from a site where this is demonstrated but I can't get it to work. I've made a up a codepen for it. If anyone can spot what's going wrong I'd love to hear it. Thanks
https://codepen.io/mrjonoces/pen/GRmGWpx
h1 = document.getElementById("post_title")
function updateText(e) {
multiplierWidth = e.offsetX / window.innerWidth;
randomWeight = multiplierWidth * (700 - 100) + 100;
h1.fontVariationSettings = "\"wght\" " + randomWeight;
}
window.addEventListener("mousemove", updateText)
You need to make sure you're actually loading the variable font.
https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap
will load only the regular single font-weight.
Besides, google might return variable
@font-face
rules to some browsers.Open a google font css url like
https://fonts.googleapis.com/css2?family=Roboto+Mono:[email protected]
("100..700" will work as a range selection query) for instance in firefox. The result would be:The 2 font weight values
font-weight: 100 700
indicate we got the variable font.Example snippet