setTimeout Jquery帮助

时间:2011-09-27 08:49:42

标签: jquery jquery-ui jquery-plugins

我如何设置1秒的timetime,以便进行以下动画,我尝试使用SetTimeout,但它没有用,继承人代码

$(document).ready(function(){
$('.caption_logo .flying-text').css({opacity:0});
$('.caption_logo .active-text').animate({opacity:1, marginLeft: "-350px"}, 500);

var intval = setInterval(changeText, 300);    

function changeText(){
    var $activeText = $(".caption_logo .active-text");

    var $nextText = $activeText.next();
    if($activeText.next().length == 0) clearInterval(intval);

    $nextText.css({opacity: 0}).addClass('active-text').animate({opacity:1, marginLeft: "-350px"}, 500, function(){

    $activeText.removeClass('active-text');                                           
    });
}
});  

1 个答案:

答案 0 :(得分:0)

您可以尝试使用如下的setTimeout函数:

$(document).ready(function(){
    $('.caption_logo .flying-text').css({opacity:0});
    $('.caption_logo .active-text').animate({opacity:1, marginLeft: "-350px"}, 500);

    setTimeout(changeText, 300);    

    function changeText(){
        var $activeText = $(".caption_logo .active-text");

        var $nextText = $activeText.next();

        if($activeText.next().length > 0) setTimeout(changeText, 300);

        $nextText.css({opacity: 0}).addClass('active-text').animate(
            {
                opacity:1, 
                marginLeft: "-350px"
            }, 
            500, 
            function(){
                $activeText.removeClass('active-text');                                           
            }
        );
    }
}); 

希望它适合你。