【问题标题】:jquery transit animation and .stop() fx queuejquery 中转动画和 .stop() fx 队列
【发布时间】:2012-08-09 22:29:04
【问题描述】:

首先,jQuery Transit 非常棒。如果您还没有看过它,请查看http://ricostacruz.com/jquery.transit/ 并感到惊讶!

但一个问题是,虽然它声称使用 jQuery 的效果队列,而且似乎在大多数情况下,但我无法让 jQuery 的 .stop() 方法使用它。

我在这里发布了一个小提琴:http://jsfiddle.net/nicholasstephan/sTpa7/

如果单击动画按钮,则会使用标准的 jQuery .animate() 将框慢慢向右移动。如您所料,点击停止将停止动画。点击重置也会停止动画并将盒子放回它开始的地方。

如果你点击转换,它应该做同样的事情......但它没有......

这里发生了什么?有人知道解决方法吗?

谢谢。

【问题讨论】:

  • 我正在寻找相同问题的解决方案。您是否尝试过以下代码:github.com/rstacruz/jquery.transit/issues/18
  • 我没试过。很好的发现。我正在为我现在需要停止的动画使用普通的旧 jQuery 动画,但我一定会看看。

标签: jquery animation transition


【解决方案1】:

这是一个可行的解决方案。

尝试创建一个新的转换函数来排队一个额外的回调。这个回调可以在动画被 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)

【讨论】:

    【解决方案2】:

    正如@Jason More 所说,我在那个线程中查找,发现存在一个fork 并且有一个名为transitionStop() 的函数(并且要清除所有剩余的动画,您还应该调用clearQueue()) ,但考虑到这个 fork 的最后一次提交大约是一年前,而原始 TransitJS 的最后一次提交大约是 3 个月前,也许你会错过使用该 fork 的一些功能。
    但是对于我需要的,这是最快的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多