2012-08-09 89 views
5

首先,jQuery Transit的岩石。如果你還沒有看到它,請查看http://ricostacruz.com/jquery.transit/並驚訝!jquery中轉動畫和.stop()fx隊列

雖然一個問題是,雖然它聲稱使用jQuery的效果隊列,似乎在大多數情況下,我不能讓jQuery的.stop()方法來使用它。

我已經發布了小提琴這裏:http://jsfiddle.net/nicholasstephan/sTpa7/

如果您單擊動畫按鈕,一個標準的jQuery .animate()用於盒子緩緩移動到右邊。正如你所期望的那樣,停止將停止動畫。點擊重置也會停止動畫並將其放回到開始位置。

如果單擊過渡,它應該做同樣的事情......但事實並非如此......

這是怎麼回事嗎?任何人都知道這個解決方法?

謝謝。

+0

我正在尋找相同問題的解決方案。你有沒有嘗試下面的代碼:https://github.com/rstacruz/jquery.transit/issues/18? – 2012-08-13 19:52:38

+0

我還沒有試過。很好的發現。我開始使用簡單的舊jQuery動畫來製作我的動畫,但現在需要暫停,但我肯定會看看這個。 – nicholas 2012-08-15 03:10:22

回答

4

以下是可能有效的解決方案。

嘗試創建一個將額外回調排隊的新轉換函數。這個回調可以在動畫通過stop出隊後清理。清除和跳過指令但是沒有收到舊的停止功能。但是我們可以爲此創建一個新的停止功能。這是剛纔輸入瀏覽器,並沒有經過充分測試

(function($){ 
    $.fn.stopableTransition = function (...){ 
     var skip = false 
     var clear = false 
     this.handle("stopTransition", function(doclear, doskip){ 
      skip = doskip; clear = doclear; 
     }) 
     this.transition(...) 
     this.queue(function(){ 
      if(skip){ 
       //todo: ensure animation is removed from css 
       //todo: move object to where the animation would have finished 
      } 
      else 
      { 
       //todo: ensure animation is removed from css 
       //todo: make sure object stays at its current position 
      } 

      if(clear){ 
       skip = false 
       clear = false 
       $(this).clearQueue() 
      } 
      else 
      { 
       skip = false 
       clear = false 
       $(this).dequeue() 
      } 

     }) 
    } 
    $.fn.stopTransition = function (clear, skip){ 
     clear = (typeof(clear) === 'undefined') ? false : clear; 
     skip = (typeof(skip) === 'undefined') ? false : skip; 
     this.triggerHandler("stopTransition", [clear, skip]) 
     this.dequeue(); 
    } 
})(jQuery) 
+0

4 upvotes,所以有誰測試過它? – mu3 2016-02-22 00:09:57

0

正如@Jason更說,我在該線程擡頭一看,我發現了一個fork存在,並且有一個名爲transitionStop()功能(和清除所有剩餘動畫你也應該調用clearQueue()),但考慮到這個分支有一年前最後一次提交的事實,並且最初的TransitJS有3個月前的最後一次提交,也許你會錯過使用那個分支的一些特性。
但爲了我所需要的,這是最快的方法。