不同元素的 jQuery 排队动画问题
大家好,我在链接动画时遇到问题,我的情况是:
HTML
...
<div id="content" class="home-layout clearfix">
<section class="home-related">
...
</section>
<section class="search">
<div class="left">
<div class="panel">
...
</div>
</div>
<div class="right">
<a class="someclass" href="#">CLICK</a>
</div>
</section>
</div>
...
JS
...
setupPanel : function() {
var $container = $("#content"),
$toHide = $("#content section.home-related"),
$toShow = $("#content div.left"),
$toShowContent = $('#content div.left div.panel'),
widthOpen = '602px',
positionOpen = '-600px',
widthClose = '30px',
positionClose = '0',
durationSlide = 300,
durationFade = 300;
if(MyApp.vars.searchAperto == false){
MyApp.vars.searchAperto = true;
//ANIMATION ONE
$toHide.fadeOut(durationFade, function(){
$toShow.animate({
width: widthOpen,
left: positionOpen
}, durationSlide, function(){
$toShowContent.fadeIn(durationFade);
});
});
}else{
MyApp.vars.searchAperto = false;
//ANIMATION TWO
$toShowContent.fadeOut(durationFade, function(){
$toShow.animate({
width: widthClose,
left: positionClose
}, durationSlide, function(){
$toHide.fadeIn(durationFade);
});
});
}
},
...
一切正常。如果我点击“CLICK”,“ANIMATION ONE”就会正确执行;在动画结束时,如果我再次单击“单击”,“动画二”将正确执行;如果我在动画一正在进行时(或动画二正在进行时)单击“单击”,一切都会变得混乱......我想要的行为是,如果我在动画正在播放时单击“单击”继续,动画继续播放直到结束,之后,另一个动画开始播放,如果我再次单击相同的行为,依此类推...基本上我想要一个队列:动画一,动画二,动画一个等等...取决于我的点击。
我尝试使用应用于 $container 的 .queue() 和 .dequeue() 方法,但没有成功;我无法判断点击时我的应用程序应该将动画放入队列中而不是执行它...
请帮助我,我快疯了:D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到您采取了在
这实际上是解决这个问题的一个非常好的方法。希望您只是在理解.queue()
的方法>$container.queue() 时遇到问题
这段代码将为您工作:jQuery 中使用的默认队列将自动启动,因此您无需搞乱
.dequeue()
根本。队列函数的第一个参数将是next
- 该函数将使下一个队列函数出队,因此您可以使用next()
将队列推进到它的位置。下一步。I see you took an approach of using
.queue()
on$container
which is actually a really good solution to this problem. Hopefully you were just having problems understanding.queue()
and this code will work for you:The default queue used in jQuery will auto-start, so you don't need to mess with
.dequeue()
at all. The first argument to a queue function is going to benext
- a function that will dequeue the next queue function, so you can usenext()
to advance the queue to its next step.