How to make this jQuery animation code loop forever?

前端 未结 3 971
清歌不尽
清歌不尽 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:39

    Create a recursive and self-executing function and use it as the final callback:

    p.s. Took the liberty to clean up your code.

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

提交回复
热议问题