Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过JavaScript拖动平滑滑块_Javascript_Jquery_Html_Json - Fatal编程技术网

通过JavaScript拖动平滑滑块

通过JavaScript拖动平滑滑块,javascript,jquery,html,json,Javascript,Jquery,Html,Json,我有以下代码。它只需循环遍历和对象,并以HTML的形式将对象键显示为滑动条 jQuery(函数($){ $(“#阈值”).change(updateThreshold); 函数updateThreshold(){ var thresholdinex=parseInt($('#threshold').val(),10); $(“#foldchange_threshold”).html(foldchange_thresholds[thresholdIndex]); }; var foldchang

我有以下代码。它只需循环遍历和对象,并以HTML的形式将对象键显示为滑动条

jQuery(函数($){
$(“#阈值”).change(updateThreshold);
函数updateThreshold(){
var thresholdinex=parseInt($('#threshold').val(),10);
$(“#foldchange_threshold”).html(foldchange_thresholds[thresholdIndex]);
};
var foldchange_阈值=[];
var mydata={“3”:[“c”,“d”],
“3.5”:[“j”,“k”],
“1.5”:[“a”、“b”],
“0.5”:[“c”、“d”],
“2.0”:[“e”、“f”],
“2.5”:[“x”,“y”]};
Object.keys(mydata).sort().forEach(函数(键){
foldchange_阈值。按下(键);
});
$(“#阈值”).attr('max',foldchange_阈值.length-1);
});



我不确定它是否能解决任何问题,但您可以通过不让jquery每次都查找元素来提高效率

var $foldchange = $("#foldchange_threshold");
$('#threshold').change(function() {
  var thresholdIndex = parseInt($(this).val(), 10);
  $foldchange.html(foldchange_thresholds[thresholdIndex]);
});

根据运营商的要求更新

$(函数(){
var foldchange_阈值=[];
var mydata={“3”:[“c”,“d”],
“3.5”:[“j”,“k”],
“1.5”:[“a”、“b”],
“0.5”:[“c”、“d”],
“2.0”:[“e”、“f”],
“2.5”:[“x”,“y”]};
Object.keys(mydata).sort().forEach(函数(键){
foldchange_阈值。按下(键);
});
var$foldchange=$(“#foldchange_阈值”);
$('#阈值')。更改(函数(){
var thresholdIndex=parseInt($(this).val(),10);
$foldchange.html(foldchange_阈值[thresholdIndex]);
}).attr('max',foldchange_阈值。长度-1);
});



在我的浏览器中,它很流畅。它只是循序渐进。没有这样的滞后,我也没有滞后。像你设计的那样循序渐进to@forgivenson:除了循序渐进,还有其他选择吗?我的意思是比台阶更平滑。你能举个跑步的例子吗?e、 g.不确定为什么有必要这样做?代码片段的问题是,它需要我复制整个代码,这使得更难准确地看到更改了什么。我上面的例子对你来说还不够吗?