Fading in/out a jquery list

后端 未结 5 417
误落风尘
误落风尘 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:07

    Most of these look like good solutions. I may be reading into your question, but I'm assuming the advantage of fading each in & out individually is so you can stagger the transitions.

    If that's the case, I'd recommend using jQuery's .delay() method:

    https://api.jquery.com/delay/

    I've forked the jsfiddle @arun made to show you how it could be done:

    http://jsfiddle.net/Lgwm8/1/

    function startAnimations() {
      var list = $("#intro li");
      list.hide();
      list.each(function (i, li) {
        $(li).delay(i * 500).fadeIn(3000, function () {
          $(li).fadeOut(3000);
        });
      });
    }
    startAnimations();
    

提交回复
热议问题