Fading in/out a jquery list

后端 未结 5 347
误落风尘
误落风尘 2021-01-27 23:12

I\'m trying to write a jquery function that loops through an unordered list (the ul element having the id \"intro\") and individually fades in and fades out each element. This

5条回答
  •  北海茫月
    2021-01-28 00:03

    You can use:

    function fadeLi(elem) {
        elem.delay().fadeIn().delay(1500).fadeOut(500, function () {
            if (elem.next().length > 0) {
                fadeLi(elem.next());
            } else {
                fadeLi(elem.siblings(':first'));
            }
        });
    }
    
    $(function () {
        $('#intro li').hide();
        fadeLi($('ul li:first'));
    });
    

    Fiddle Demo

提交回复
热议问题