简体   繁体   English

如何排序一个div的隐藏顺序,然后使用jQuery动画显示另一个div?

[英]How to sequence the hiding of one div then show another using jQuery animations?

I have a code which should show the next div from my form: 我有一个代码,应该显示表单中的下一个div:

Next button: 下一步按钮:

$('.site.active').removeClass('active').hide().next().show().addClass('active');

Back button: 返回键:

$('.side.active').removeClass('active').hide().prev().show().addClass('active');

All works fine for me but how can I animate my show and hide like in this form here: http://azmind.com/demo/bootstrap-long-multi-step-form/ 一切对我来说都很好,但如何在此显示动画并隐藏这种形式: http : //azmind.com/demo/bootstrap-long-multi-step-form/

In my form the transition is very hard hide last and show next. 以我的形式,过渡很难隐藏到最后,然后再显示。

You can nest animations by using callbacks. 您可以使用回调嵌套动画。 When an animation finishes, it's callback function is called. 动画结束时,将调用其回调函数。 Inside that you can perform another animation on another element. 在其中,您可以在另一个元素上执行另一个动画。

In your case, you'll want to select the element with the .active class, fade it out, in that fade out's callback remove the .active and call .next() , fade that "next" element in, then call .addClass() in the fade in's callback. 在您的情况下,您需要选择具有.active类的元素, .active淡出,在该逐渐消失的回调中,删除.active并调用.next() ,使该“ next”元素进入其中,然后调用.addClass()在淡入的回调中。

 $(function() { $('.next').on('click', function() { $('.active').fadeOut('slow', function() { // this gets called when the fade out finishes $(this).removeClass('active').next().fadeIn('slow', function() { // this gets called when the fade in finishes $(this).addClass('active'); }); }); }); }); 
 .page { display: none; width: 100px; height: 100px; } .first { display: block; background: red; } .second { background: blue; } .third { background: green; } .active { color: white; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="page first active">first page</div> <div class="page second">second page</div> <div class="page third">third page</div> <button class="next">Next</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM