我试图在值上升或下降时获取滑块的值。
$(document).ready(function() {
var valMap = [1,2,3,4,5,6,7,8,9,10];
var counter = null;
var slider = $( "#slider" ).slider({
disabled: false,
animate: true,
min: 0,
max: valMap.length-1,
values: [0],
slide: function( event, ui ) {
$( "#zomlevel" ).val(valMap[ui.values[0]] + "x");
slider.slider("option", "animate", "slow");
counter++;
if(counter increments){
alert("COUNTER INCREMENTS");
}
if(counter decrement){
alert("COUNTER DECREMENTS");
}
}
});
});
如果我向右滑动滑块,它应该增加,如果我向左滑动滑块,它应该减少。我怎么能在滑块中做到这一点?
答案 0 :(得分:1)
尝试类似
的内容jQuery(function($){
var valMap = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var counter = null, value= 0;
var slider = $("#slider").slider({
disabled : false,
animate : true,
min : 0,
max : valMap.length - 1,
slide : function(event, ui) {
//$("#zomlevel").val(valMap[ui.values[0]] + "x");
slider.slider("option", "animate", "slow");
counter++;
},
change: function(){
var val = $(this).slider('value');
console.log(val, value)
if(value < val) {
console.log('incremented')
} else if(value > val){
console.log('decremented')
}
value = val;
}
});
});
演示:Plunker