gpt4 book ai didi

javascript - 范围 slider - 滑动期间运行功能不起作用?

转载 作者:行者123 更新时间:2023-12-03 12:38:32 28 4
gpt4 key购买 nike

我正在使用noUISlider在页面上允许人们选择一个值。然而,noUISlider 的话,当一个人滑动时,我希望它运行一个基本上检查数字的函数,如果数字低于某个值,它将在 div 中显示文本。

问题是该值记录在隐藏输入中,但显示文本的功能从未起作用。

这是我的函数代码:

var heightSlide = $('.height-noUI');
var onSlide = function(){
var slideHeight = "$('input[name=CAT_Custom_8]').val();"
if(slideHeight <= 20){
$('.height-noUI-text').text('Short');
}else if(slideHeight <= 40){
$('.height-noUI-text').text('Short to Medium');
}else if(slideHeight <= 60){
$('.height-noUI-text').text('Medium');
}else if(slideHeight <= 80){
$('.height-noUI-text').text('Medium to Tall');
}else if(slideHeight <= 100){
$('.height-noUI-text').text('Tall');
}
};
heightSlide.on('slide', onSlide);

这是一个jsFiddle带有工作 slider 的代码。

如何更新我的代码以使其在 slider 滑动时文本显示在 div 中?

最佳答案

我解决了你的问题。检查代码以了解。

这是一个jsfiddle

$(function() {

$(".height-noUI").noUiSlider({
range: [0, 100],
start: 0,
range: {
'min': [0],
'max': [100]
},
step: 20,
connect: "lower",
serialization: {
lower: [
$.Link({
target: $("input[name=CAT_Custom_8]")
})
],
format: {
decimals: 0
}
}
});

var heightSlide = $('.height-noUI');
var onSlide = function(){
var slideHeight = $('.noUi-origin').position().left / $('.noUi-origin').parent().width() * 100; //Here is the trick.
if(slideHeight <= 20){
$('.height-noUI-text').text('Short');
}else if(slideHeight <= 40){
$('.height-noUI-text').text('Short to Medium');
}else if(slideHeight <= 60){
$('.height-noUI-text').text('Medium');
}else if(slideHeight <= 80){
$('.height-noUI-text').text('Medium to Tall');
}else if(slideHeight <= 100){
$('.height-noUI-text').text('Tall');
}
};
heightSlide.on('slide', onSlide);

});

关于javascript - 范围 slider - 滑动期间运行功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23622039/

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