jquery传输动画和.stop()fx队列

nic*_*las 5 jquery animation transition

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

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

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

如果单击动画按钮,.animate()则使用标准jQuery 将框慢慢移动到右侧.正如您所期望的那样,按下停止将停止动画.点击重置也会停止动画并将框放回到它开始的位置.

如果你点击过渡,它应该做同样的事情......但它不...

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

谢谢.

小智 4

这是一个可能有效的解决方案。

尝试创建一个新的转换函数来对额外的回调进行排队。此回调可以在动画因停止而出列后进行清理。然而,清除和跳过指令不会从旧的停止功能中收到。但我们可以为此创建一个新的停止函数。这只是在浏览器中输入并且完全未经测试

(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)
Run Code Online (Sandbox Code Playgroud)