jQuery slideshow loop fail

后端 未结 1 570
猫巷女王i
猫巷女王i 2021-01-19 19:33

I\'ve been trying to implement snook.ca\'s Simplest jQuery Slideshow, but when applied to child elements inside a

    instead of a straightforward stack
相关标签:
1条回答
  • 2021-01-19 19:53

    Just break your chaining after selecting the next li. If there is no next li, the length of the result set will be 0. When that happens, loop back to the beginning. Then, just finish your setup. Here is a revision on your JSBin code that shows it working:

    $('header nav li').not('.current').children('p').hide();
    setInterval(function(){
      var $next = $('header nav li.current').children('p').hide()
      .parent('li').removeClass()
      .next('li');
    
      if(!$next.length) $next = $('header nav li:first');
    
      $next.addClass('current')
      .children('p').show();
    },3000);
    
    0 讨论(0)
提交回复
热议问题