2013-02-04 34 views
0

我使用兩個手柄設置了我的jqueryUI滑塊。其變化事件處理程序如下所示:JqueryUI滑塊讓更改事件處理程序等待另一個更改事件

change: function(event, ui){ 
    $("#priceFilterForm").submit(); 
}, 

只要移動一個句柄,它就會觸發表單。


我想change事件處理程序會那樣:

  • 如果變更事件被觸發等待3秒
  • 如果另一個變化事件觸發復位3秒計時器
  • 如果在3秒內沒有其他更改事件提交表格

您能否請我提示技術e如何實現這一行爲。


解決方案感謝對加里:

var timer = $.timer(function(){ 
    $("#priceFilterForm").submit(); 
}); 

// slider options: 

slide: function(event, ui){ 
    timer.pause(); 
    // ... 
}, 
change: function(event, ui){ 
    timer.stop(); // Not sure if stop is needed here.. 
    timer.set({ time : 1500, autostart : true }); 
} 

+不要忘了,包括計時器插件安裝到你的JavaScript

+0

你可以看看了jQuery插件hoverIntent,也許嘗試修改它'.change',而不是'.hover',或者只是得到一個想法它是如何工作的:http://archive.plugins.jquery.com/project/hoverIntent除了使用不同的輸入監聽器之外,這個想法與您的想法完全相同。 – Joey

回答

0
var timer = $.timer(function() { 
      alert('This message was sent by a timer.'); 
    }); 

    timer.set({ time : 5000, autostart : true }); 

    timer.set(options); 
    timer.play(reset); // Boolean. Defaults to false. 
    timer.pause(); 
    timer.stop(); // Pause and resets 
    timer.toggle(reset); // Boolean. Defaults to false. 
    timer.once(time); // Number. Defaults to 0. 
    timer.isActive // Returns true if timer is running 
    timer.remaining // Remaining time when paused 

演示

http://jchavannes.com/jquery-timer/demo

下載

http://code.google.com/p/jquery-timer/downloads/detail?name=jquery-timer.zip 查看源

http://code.google.com/p/jquery-timer/source/browse/