javascript - Range slider with min and max values limites
问题描述
I have this code, which displays a range slider with values from 1 to 100 and 4 squares of different values, i have the minimum value limite handler on the range line, as i increase the value using the handler, the squares that are bellow that value start the disapeer.
Now i want to add the maximum handler limite on the same line. ( One line with 2 handlers )
Anybody knows how ?
Thanks.
function sliderChange(val) {
document.getElementById('sliderStatusMin').innerHTML = val;
function displayItem(val) {
$('.item').filter(function() {
var price = $(this).data('price');
if (price < val) {
return price;
}
}).hide();
$('.item').filter(function() {
var price = $(this).data('price');
if (price > val) {
return price;
}
}).show();
}
displayItem(val);
}
.item {
width: 100px;
height: 100px;
background-color: red;
}
<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous">
</script>
<input class="first" type="range" min="0" max="100" value="50" step="2" onChange="sliderChange(this.value)" />
<br /><br /> Minimum Value = <span id="sliderStatusMin"></span>
<div class="item" data-price="90">90</div>
<div class="item" data-price="20">20</div>
<div class="item" data-price="70">70</div>
<div class="item" data-price="40">40</div>
解决方案
Take a look at the jQuery UI http://jqueryui.com/slider/#range or take a look at this answer https://stackoverflow.com/a/31083391/7993505 for a variant without jQuery UI.
推荐阅读
- javascript - 如何显示索引数组的特殊词?
- javascript - 在操作数是类型化数组的 JavaScript 中,最有效的乘法、加法、减法和除法方法是什么?
- python - Django多对多字段未正确保存在数据库中
- function - 从另一个类/文件调用 ContentView 中的函数
- javascript - GravityForms - 通过 javascript 触发价格计算
- php - 如果 $_SESSION['uname'] 不等于 "teacher",返回主页面
- c++ - 按行/索引从备忘录复制文本
- flutter - 尝试在调试模式下运行 Flutter Android 应用程序时,Android 应用程序构建失败
- javascript - 将多个商品添加到购物车
- python - 如何安装 bsddb3?