简体   繁体   English

jQuery队列排序动画

[英]Jquery queue sequenced animations

I have the following code that shows a slideshow. 我有以下显示幻灯片的代码。 My problem is that one element is not fully hidden (fadeout) before the next one (fade in) appaears, causing me to have to fix it with CSS, which is not the ideal scenario.. this is the code: 我的问题是,一个元素在下一个(淡入)出现之前没有完全隐藏(淡入淡出),这导致我不得不使用CSS对其进行修复,这不是理想的情况..这是代码:

setInterval(function() { 
  $('#slides > li:first')
    .fadeOut(500)
    .next()
    .fadeIn(500)
    .end()
    .appendTo('#slidelist');
},  2000);

I've tried the following without success: 我已经尝试了以下方法但没有成功:

setInterval(function() { 
  $('#slides > li:first')
    .fadeOut(500).delay(500)
    .next()
    .fadeIn(500)
    .end()
    .appendTo('#slidelist');
},  2000);

Any ideas how can I get the element fully faded out before the next one fades in? 有什么想法可以在下一个元素淡入淡出之前让元素完全淡出吗?

If you want the fadeIn to start after your previous fadeOut finishes, use the callback function parameter to execute the fadeIn. 如果您希望在上一个fadeOut完成之后开始fadeIn,请使用回调函数参数执行fadeIn。 The callback function will execute after the first action (fadeOut) completes. 回调函数将在第一个动作(fadeOut)完成后执行。

Here's an example of 2 divs - 1 fading out, then 1 fading in. I used the animate function on opacity, which is essentially the same as fadeIn / fadeOut. 这是2个div的示例-淡出1次,然后淡入1次。我在不透明度上使用了animate函数,该函数基本上与fadeIn / fadeOut相同。

Animate: http://api.jquery.com/animate/ 动画: http//api.jquery.com/animate/
FadeOut: http://api.jquery.com/fadeout/ FadeOut: http//api.jquery.com/fadeout/
FadeIn: http://api.jquery.com/fadein/ FadeIn: http ://api.jquery.com/fadein/

jsfiddle: http://jsfiddle.net/biz79/du9utty8/ jsfiddle: http : //jsfiddle.net/biz79/du9utty8/

var $divs = $('div');

$divs.eq(0).animate( {"opacity":"0"},1000 , function() {
    $divs.eq(1).animate( { "opacity":"1" },1000)
})

Hopefully you can modify your code to apply this solution. 希望您可以修改代码以应用此解决方案。 If not, post a fiddle and let me know, and I can help adjust your code. 如果没有,请发个小提琴让我知道,我可以帮助您调整代码。

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

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