2010-02-23 40 views
2

我正在使用jQuery UI對話框讓用戶知道他的請求正在進行,而客戶端正在處理一些數據。然而,正如大家都知道的那樣,它比firefox處理的時間要長得多。確保進度對話框至少顯示一段最短時間的最佳模式是什麼,因此它不會在Firefox中閃爍,並且即使定時器到期,對話框也會一直保持,直到瀏覽器結束處理?確保jQuery進度對話框至少顯示一些最短時間

回答

3

你可以用幾種方式解決它,儘管它們本質上都是做一些排隊派生的。

例如:

$("#startLink").click(function(){ 
    var $dialog = $(".dialog"); 
    $dialog.dialog({ 
     open: function(e, ui){ 
      // delay any close operations for at least 2 seconds 
      $dialog.queue(function(){ 
       setTimeout(function(){ 
        $dialog.dequeue(); 
       }, 2000); 
      }); 
      // if you're using jQuery 1.4, you can do this instead 
      // $dialog.delay(2000); 
     } 
    }); 

    // do some processing here 

    $dialog.queue(function(){ 
     $dialog.dialog('close'); 
     $dialog.dequeue(); 
    }); 
}); 

無論如何,你要真正做的是確保使用內置的排隊系統給定的延遲。你可以在不使用隊列系統的情況下完成它,但這是另一個例子。

+0

太棒了,像魅力一樣工作。非常感謝。 – Ryan 2010-02-23 21:59:56

+0

很好的答案@BBonifield!很好的使用最佳實踐! – 2010-02-23 22:33:47