我从搜索中发现的一些相关问题:
我已经阅读了有关 jquery 的 animate() 的文档,但在找出解决问题的方法时遇到了一些困难。
我要做的是在多个元素上排列一系列动画。我希望动画按顺序执行,即我希望一个元素上的当前动画阻止其自己元素上的动画,但不阻止另一个元素上的动画。
最后,我希望能够取消其中一个元素上的动画,但允许其他元素上的动画继续。
我认为命名的 jquery 队列是我想要的,但是尝试这给了我从未开始的动画(我认为这是由于“fx”队列不存在于每个其他队列上的魔力)。
提前致谢!
编辑:
这就是我正在寻找的东西:
function someAnimationWrapper(queueName, element, animation) {
///<summary>
/// Places the animation specified into the queue of animations to be
/// run on that element. The animation queue is a named queue so
/// animations in the queue can be stopped at any time.
///</summary>
///<param name="queueName" type="String">
/// The name to assign to the element's animation queue.
///</param>
///<param name="element" type="jQuery">
/// jQuery object to perform the animations on.
///</param>
///<param name="animation" type="Object">
/// Animation properties for the animation call.
///</param>
// TODO: If magic needs to be done here this is a placeholder
element.animate(animation);
}
function magicallyStopMyQueue(queueName, clearQueue, jumpToEnd) { // May take element, whatever I need to get the job done
///<summary>Mirrors jQuery.prototype.stop(), but with the named queue.</summary>
///<param name="queueName" type="String">
/// Animation queue to stop.
///</param>
///<param name="clearQueue" type="Boolean">
/// See jQuery.prototype.stop()
///</param>
///<param name="jumpToEnd" type="Boolean">
/// See jQuery.prototype.stop()
///</param>
// TODO: some magics here
}
var e1 = $('.myDiv1'),
e2 = $('.myDiv2');
someAnimationWrapper('firstQueue', e1, { properties: { left: '-=16' }, duration: 100 });
someAnimationWrapper('firstQueue', e1, { properties: { left: '-=16' }, duration: 100 });
someAnimationWrapper('firstQueue', e1, { properties: { left: '-=16' }, duration: 100 });
someAnimationWrapper('secondQueue', e2, { properties: { left: '-=16' }, duration: 100 });
someAnimationWrapper('secondQueue', e2, { properties: { left: '-=16' }, duration: 100 });
someAnimationWrapper('secondQueue', e2, { properties: { left: '-=16' }, duration: 100 });
// Now I want to stop the first one
magicallyStopMyQueue('firstQueue', true, true);