简体   繁体   English

使用jQuery淡出DIV并淡入下一个DIV

[英]Fade out DIV and fade in next DIV with jQuery

Im trying to build a slider from scratch only im a bit stuck, I basically want each div to fade out and the next one to fade in straight afterwards, once each div has faded in, i want the image within that to animate, I've made a fiddle to try and explain. 我试图从头开始构建一个滑块,只是有点卡住了,我基本上希望每个div淡出,然后下一个逐渐淡入,一旦每个div淡入,我希望其中的图像具有动画效果,我就是我做了一个小提琴来尝试解释。 Thanks for any help! 谢谢你的帮助!

http://jsfiddle.net/FeqkB/2/ http://jsfiddle.net/FeqkB/2/

Basically, you have to make use of callback functions when you want to create sequential animations. 基本上,要创建顺序动画时必须使用回调函数。 If you do it the way it is done in your fiddle, you launch all the effects at the same time, resulting in a messy behavior. 如果按照提琴演奏的方式进行操作,则会同时启动所有效果,从而导致混乱的行为。 The functions fadeIn, fadeOut and animate all take a callback function. 函数fadeIn,fadeOut和animate都带有回调函数。 Let's say you want fadeIn, then animate, then fadeOut. 假设您要淡入,然后进行动画处理,然后淡出。

  1. fadeIn is called with a callback which will animate 使用回调进行淡化,该回调将进行动画处理
  2. animate is called with a callback which will fadeOut 带有回调的animate将被淡出

I forked your fiddle to give you an example, but I did it just for the first div. 我分叉了您的小提琴,给您举了一个例子,但我只是在第一时间就做了。 If you understand this mechanism, it will be easy to extend it for any number of effects. 如果您了解此机制,可以很容易地将其扩展为多种效果。 Here it is : http://jsfiddle.net/bBxUQ/1/ 在这里是: http : //jsfiddle.net/bBxUQ/1/

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

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