Javascript jQuery幻灯片标题在循环结束前停止

Javascript jQuery幻灯片标题在循环结束前停止,javascript,jquery,easing,Javascript,Jquery,Easing,幻灯片标题停止不完成循环。 完成幻灯片的代码中缺少什么 <div id="overflow-animate"> <div id="animate-container"> <h1 class="giga remove-bottom">title1</h1> <h1 class="giga remove-bottom">title2</h1> <h1 class="g

幻灯片标题停止不完成循环。 完成幻灯片的代码中缺少什么

<div id="overflow-animate">
    <div id="animate-container">
        <h1 class="giga remove-bottom">title1</h1>
        <h1 class="giga remove-bottom">title2</h1>
        <h1 class="giga remove-bottom">title3</h1>
        <h1 class="giga remove-bottom">title4</h1>
        <h1 class="giga remove-bottom">title5</h1>
    </div>
</div>

标题1
标题2
标题3
标题4
标题5
jQuery:

//SET DELAY TO MODIFY THE DELAY OF THE INTRO ANIMATION
//INTRO ANIMATION
var delay = 1200;
var titleheight = $('#animate-container h1').outerHeight();
var count = $('#animate-container').height() / titleheight;

for (var i = 0; i < count; i++) {
    var distance = titleheight * i;
    $('#animate-container').delay(delay).animate({'top': '-' + distance + 'px'}, 400, 'easeOutBounce');
}

$('#animate-container').delay(800).animate({'top': '0px'}, 500, 'easeOutBounce');

if ($(".home .cover i").length > 0 && $(window).width() > 767) {
    $('.home .cover i').delay((count * delay) + (delay * 2)).animate({'top': $('.cover i').offset().top - 180}, 500, 'easeOutBounce', function() {
        //$('.cover h3').fadeIn(500);
    });
}
//END WINDOW ANIMATION
//设置延迟以修改简介动画的延迟
//介绍动画
无功延迟=1200;
var titleheight=$(“#为容器h1制作动画”).outerHeight();
var count=$(“#设置容器动画”).height()/titlheight;
对于(变量i=0;i0&$(window.width()>767){
$('.home.cover i').delay((count*delay)+(delay*2)).animate({'top':$('cover i').offset().top-180},500,'easeOutBounce',function(){
//美元("封面h3").法代因(500美元);;
});
}
//结束窗口动画

这应该可以解决您的问题:

var container = $('#animate-container'),
    gigaH1 = container.find('h1'),
    titleHeight = gigaH1.height() + parseInt(gigaH1.css('margin-top'), 10);
(function animateH1() {
    for (var i = 0; i < gigaH1.length; i++) {
        container.delay(1200).animate({
            'top': '-' + titleHeight * i
        }, 400, 'easeOutBounce');
    }
    container.delay(800).animate({ 'top': 0 }, 500, 'easeOutBounce', animateH1);
}());
首先,代码缓存一些变量(
container
gigaH1
),因为它们不会在每次运行函数时都更改。然后计算将每个H1移出视图所需的偏移量

下面的函数是自调用的,只需运行您的原始代码(稍作调整)。最后一个动画具有
animateH1()
函数本身作为回调函数,因此整个动画完成后将再次运行


它在这里工作:

请将整个代码发布到JSFIDLE上,以便更容易阅读……我更新了您的问题,将其隔开一些,并提供了一个JSFIDLE供您使用。编辑小提琴以适应设置,然后编辑这里的链接。同样,你的问题不清楚。请重新查看并尝试编辑它。
#animate-container {
    position: relative;
    float: left;
    top: 0;
}
#overflow-animate {
    overflow: hidden;
    height: 79px;
}