Simple JQuery Fade ticker

后端 未结 4 1642
暖寄归人
暖寄归人 2021-01-24 16:18

I\'ve looked at multiple tickers and they are all far to weighted. I\'m after a very simple fadeIn() fadeOut() JQuery ticker for a list of elements to display titles.

         


        
4条回答
  •  Happy的楠姐
    2021-01-24 16:21

    Untested. This simply reschedules the fade out/in, which are chained together, on the next element after the current one completes.

    function fadeTicker( $collection, $elem, interval )
    {
         var $next = $collection.eq(($collection.index($elem) + 1) % $collection.length));
         $(elem).fadeOut( function() {
              $(next).fadeIn( function() {
                   setTimeout( function() {
                           fadeTicker( $collection, $next, interval );
                       },
                       interval
                   );
              });
         );
    );
    

    Used as:

    $(function() {
        fadeTicker( $('li'), $('li:first'), 5000 );
    }
    

提交回复
热议问题