【问题标题】:Jquery help, looping an animationJquery帮助,循环动画
【发布时间】:2011-07-07 17:35:29
【问题描述】:

我是一个 jQuery 菜鸟,我如何循环这个?如果可能的话,我可以把它整理一下,这样它就可以用更少的代码工作吗?

$(document).ready(function() {
    speech_animation();
});

 function speech_animation(){  
    $( "#b-block_wrap" ).delay(1000).fadeIn(500).animate({ top: 0}, {duration: 500,});
    $( "#p-block_wrap" ).delay(2000).fadeIn(500).animate({ top: 0,}, {duration: 500,});
    $("#first_wrap").delay(5500).fadeOut(500);
    $( "#g-block_wrap" ).delay(6000).fadeIn(500).animate({ top: 0}, {duration: 500,});
    $( "#y-block_wrap" ).delay(7000).fadeIn(500).animate({ top: 0}, {duration: 500,});
    $("#second_wrap").delay(10500).fadeOut(500);
}   

【问题讨论】:

    标签: jquery loops callback jquery-animate settimeout


    【解决方案1】:

    您可以在最后一个函数调用中使用回调,以便在最后一个函数调用完成后,它会立即调用自己。

    $(document).ready(function() {
        speech_animation();
    });
    
     function speech_animation(){  
        $( "#b-block_wrap" ).delay(1000).fadeIn(500).animate({ top: 0}, {duration: 500,});
        $( "#p-block_wrap" ).delay(2000).fadeIn(500).animate({ top: 0,}, {duration: 500,});
        $("#first_wrap").delay(5500).fadeOut(500);
        $( "#g-block_wrap" ).delay(6000).fadeIn(500).animate({ top: 0}, {duration: 500,});
        $( "#y-block_wrap" ).delay(7000).fadeIn(500).animate({ top: 0}, {duration: 500,});
        $("#second_wrap").delay(10500).fadeOut(500, speech_animation);//callback here
    }   
    

    【讨论】:

    • 我担心这不起作用,在最后两个 div 消失后我什么都没有了。
    猜你喜欢
    • 2011-10-21
    • 2010-09-23
    • 2011-03-14
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    相关资源
    最近更新 更多