我正在尝试使用一种可变字体,其权重会响应鼠标移动。我从一个展示了这一点的网站上获取了一些代码,但我无法让它工作。我已经为它制作了一个codepen。如果有人能发现出了什么问题,我很想听听。谢谢
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)