1

I implemented a slider in my jsp page and the code is as this,

$('#slider1').slider({
    range: "min",
    value: myvalue,
    min: 0,
    max: 57,
    slide: function(event, ui) {
    /*
        my backend function go here
    */
    }
});

I want to add a "mouse up time" so that after user click the slider and then pause for certain seconds, the slide function will then be triggered. I don't want the function to be triggered immediately after user release button. This makes sure that user is paused to see the function happens.

Thanks

Mike

Mike
  • 25
  • 1
  • 1
  • 4

1 Answers1

0

You can use a setTimeout to introduce a delay. See jsfiddle.

// ...
slide: function(event, ui) {
  setTimeout(function() { sliderMethod(event, ui); }, 2000); // delay trigger for 2s
}
//..
function sliderMethod(event, ui) {
  /*
    my backend function go here
  */
}
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • Thanks. If during the two seconds, the user moves the slider again, what will happen? Will the function be called twice? My aim is to make sure user has made decision and is paused for function call. – Mike Aug 30 '12 at 15:25
  • You can estimate the user delay, or utilize a **debounce plugin** to throttle the execution over a given time period. See [related SO post](http://stackoverflow.com/a/7403341/175679). – SliverNinja - MSFT Aug 30 '12 at 15:32