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