javascript - jquery ui slider comparing values after sliding -
i'm trying value of slider when value goes or goes down.
$(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"); } } }); });
if slide slider right should increment , if slide slider left should decrement. how can in slider?
try like
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; } }); });
demo: plunker
Comments
Post a Comment