javascript - 可变字体滑块
问题描述
对于一个学校项目,我正在研究使用可变字体的优势。所以我试图创建几个滑块来操纵字体。
在此我使用 Gingham 可变字体。
我已经设法让字体粗细滑块工作,但我不能为宽度滑块工作,我似乎无法解决?我想知道是否有人知道我做错了什么?
这是我的 HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Variable Fonts</title>
<link rel="stylesheet" href="css/master.css">
</head>
<body>
<h1>Adjust the sliders to modify the Variable Font: Gingham</h1>
<p id="testarea" contenteditable="true">Type Text Here</p>
<label for="slider_weight">Weight</label>
<input type="range" id="slider_weight" name="slider" value="300" min="300" max="700" step="10">
<span id="value_weight"></span>
<br>
<label for="slider_width">Width</label>
<input type="range" id="slider_width" name="slider" value="100" min="10" max="100" step="1">
<span id="value_width2"></span>
<script src="js/slider.js" charset="utf-8"></script>
</body>
</html>
这是我的 JavaScript:
document.getElementById('slider_weight').addEventListener("input", function () {
var axisValue = document.getElementById('slider_weight').value;
document.getElementById('testarea').style.fontWeight = axisValue;
document.getElementById('value_weight').innerText = axisValue;
});
document.getElementById('slider_width').addEventListener("input", function () {
var axisValue2 = document.getElementById('slider_width').value;
document.getElementById('testarea').style.fontStretch = axisValue2;
document.getElementById('value_width2').innerText = axisValue2;
});
解决方案
推荐阅读
- node.js - npm install bootstrap@4.0.0 命令给出 ENETUNREACH 错误
- python - 如何编码分类预测值?
- java - 根据字符串的不同模式拆分字符串
- json - 我有嵌套的列表对象,称为 JSON 中的剧集,那么如何根据 id 父对象而不是位置对象获取剧集列表?
- python - 数据框中的字符串编辑不使用 .replace 代码生效
- django - 如何使用 django.utils.timezone 库将日期时间从特定时区转换为其 UTC 版本?
- python - 将一个大的 numpy 数组转换为字符串
- mysql - Mysql更新多行
- angular - Angular 8 - 没有访问控制允许请求的资源上存在 Origin 标头?
- django - 删除按钮表单标签导致换行