gpt4 book ai didi

javascript - 如何使用原生 html 输入范围和 Vue.js 创建双范围 slider ?

转载 作者:行者123 更新时间:2023-12-04 13:14:19 27 4
gpt4 key购买 nike

你能帮我为原生 HTML input=range 和 Vue.js 创建一个双范围 slider (我只需要两个句柄)吗?

到目前为止我的代码:
https://jsfiddle.net/

Javascript (Vue.js)

var vm = new Vue({
el: '#app',
data: {
minAngle: 10,
maxAngle: 30
},
computed: {
sliderMin: {
get: function() {
var val = this.minAngle;
return val;
},
set: function(val) {
if (val > this.maxAngle) {
val = this.maxAngle;
}
this.minAngle = val;
console.log("minAngle:" + this.minAngle + " maxAngle:" + this.maxAngle);
}
},
sliderMax: {
get: function() {
var val = this.maxAngle;
return val;
},
set: function(val) {
if (val < this.minAngle) {
val = this.minAngle;
}
this.maxAngle = val;
console.log("minAngle:" + this.minAngle + " maxAngle:" + this.maxAngle);
}
}
}
});

HTML
<div id="app">
<input type="range" min="0" max="180" step="1" v-model="sliderMin">
<input type="number" min="0" max="180" step="1" v-model="sliderMin">
<input type="range" min="0" max="180" step="1" v-model="sliderMax">
<input type="number" min="0" max="180" step="1" v-model="sliderMax">
</div>

问题是如果它们的值低于最小值,我想限制 minSlider 和 maxSlider 的范围。所以你不会得到 maxAngle 低于 minAngle 或 minAngle 高于 maxAngle。稍后我当然会使用 CSS 在彼此的顶部制作一个 slider ,因此您会产生一种错觉,它只是一个带有两个 handle 的 slider 。我知道这有 Vue 组件,但我想知道这是否可能。

提前致谢,
波格丹

最佳答案

没关系,我找到了解决方案。原来我在不远处:)
这里是:

HTML

<div id="app">
<div class='range-slider'>
<input type="range" min="0" max="180" step="1" v-model="sliderMin">
<input type="number" min="0" max="180" step="1" v-model="sliderMin">
<input type="range" min="0" max="180" step="1" v-model="sliderMax">
<input type="number" min="0" max="180" step="1" v-model="sliderMax">
</div>
</div>

Javascript (Vue)
var app = new Vue({
el: '#app',
data: {
minPrice: "500",
maxPrice: "50000",
minValue: "25000"
},
methods: {
slider: function() {
if (this.minPrice > this.maxPrice) {
var tmp = this.maxPrice;
this.maxPrice = this.minPrice;
this.minPrice = tmp;
}
}
}
});

CSS
.range-slider {
width: 300px;
margin: auto;
text-align: center;
position: relative;
height: 6em;
}

.range-slider input[type=range] {
position: absolute;
left: 0;
bottom: 0;
}

input[type=number] {
border: 1px solid #ddd;
text-align: center;
font-size: 1.6em;
-moz-appearance: textfield;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
}

input[type=number]:invalid,
input[type=number]:out-of-range {
border: 2px solid #ff6347;
}

input[type=range] {
-webkit-appearance: none;
width: 100%;
}

input[type=range]:focus {
outline: none;
}

input[type=range]:focus::-webkit-slider-runnable-track {
background: #2497e3;
}

input[type=range]:focus::-ms-fill-lower {
background: #2497e3;
}

input[type=range]:focus::-ms-fill-upper {
background: #2497e3;
}

input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
cursor: pointer;
animate: 0.2s;
background: #2497e3;
border-radius: 1px;
box-shadow: none;
border: 0;
}

input[type=range]::-webkit-slider-thumb {
z-index: 2;
position: relative;
box-shadow: 0px 0px 0px #000;
border: 1px solid #2497e3;
height: 18px;
width: 18px;
border-radius: 25px;
background: #a1d0ff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}

fiddle :

https://jsfiddle.net/bogdanb86/3dr9ktxc/28/

关于javascript - 如何使用原生 html 输入范围和 Vue.js 创建双范围 slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61871010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com