How to make this jQuery animation code loop forever?

前端 未结 3 986
清歌不尽
清歌不尽 2021-01-06 04:18

i am trying to create a loop of text animations over a slider... i tried loop but it didnt work.. Can you please tell me how do i loop this script forever..thanks

         


        
3条回答
  •  春和景丽
    2021-01-06 04:48

    You can use recurence, the last fadeOut will execute repeat function when finish.

    function repeat() {
        $("#header").hide();
        var headerOne='I';
        var headerTwo='Am'; 
        var headerThree='So';
        var headerFour='Cool';
        $("#header").html(headerOne);
        $("#header").fadeIn(1000);
        $('#header').delay(1000).fadeOut(1000,function() {
            $(this).html(headerTwo).fadeIn(1000);
            $('#header').delay(1000).fadeOut(1000,function() {
                $(this).html(headerThree).fadeIn(1000);
                $('#header').delay(1000).fadeOut(1000,function() {
                    $(this).html(headerFour).fadeIn(1000).delay(1000).
                        fadeOut(1000, repeat); 
                });
            });
        });
    }
    
    $(document).ready(function() {
        repeat();
    });
    

提交回复
热议问题