javascript - 如何用两边的文字锚定我的滑块?
问题描述
如何在滑块的两侧添加“非常同意”和“非常不同意”的文字?
非常感谢 :)
我的代码是:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><font color="black">Right now I feel: Attentive</p>
<div class="slidecontainer">
<input type="range" min="0" max="100" value="50" step="0.01" class="slider" id="myRange">
<p><font color="black">Value: <span id="demo"></span></p>
</div>
<script>
var slider1 = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider1.value;
slider1.oninput = function() {
output.innerHTML = this.value;
}
</script>
解决方案
我为它创建了一个小提琴。
CSS
.slidecontainer {
display: flex;
flex-direction: row;
align-items: center;
margin: 20px 0;
}
.slider {
margin: 0 10px;
}
HTML
Right now I feel: Attentive
<div class="slidecontainer">
<span>Strongly agree</span><input type="range" min="0" max="100" value="50" step="0.01" class="slider" id="myRange"><span>Strongly Disagre</span>
</div>
<font color="black">Value: <span id="demo"></span>
JS
var slider1 = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider1.value;
slider1.oninput = function() {
output.innerHTML = this.value;
}
推荐阅读
- laravel - Laravel 没有选择正确的路线
- .net - AutoMapper:忽略其余部分(重新访问)
- vue.js - 使用Vue js的搜索栏过滤器
- javascript - Warning: A component is changing a controlled input to be uncontrolled in React js
- reactjs - 将 S3 请求 URL 上的静态反应网站重写为自己的 URL
- python - 基于最小距离的点身份的时间链接
- google-apps-script - Google Apps 脚本,如何将记录的数据发送到电子表格?
- spring-boot - Spring Webflux Webclient间歇性超时
- ruby-on-rails - 让 Firefox 在 Heroku 应用程序上运行:XPCOMGlueLoad 错误
- java - 当所有分区都暂停时如何停止容器?