2012-10-25 41 views
0

我有下面的代码,基本上获得了一些元素,并停止它们在6个项目。然后我得到一个按钮,当点击加载剩下的div。FadeIn一次6倍的倍数点击

我只是想要一次加载6个div。有没有人知道这样做的方式呢?

这里是JavaScript:

function click_load() { 
    var count = 0; 
    var item = $('.newsmainimages'); 
    //var itemClick = $('<a href="#">Load More</a>'); 

    $(item).each(function() { 
     if (++count == 6) { 
      $(this).parent().append('<div class="nextClick"><a href="#">Load More</a></div>'); 
     } 
     else if (count > 6) { 
      $(this).css('display','none'); 
     } 
    }); 

    $('.nextClick a').click(function() { 
     $(item).each(function(item) { 
      $(this).delay(200*item).fadeIn("slow"); 
     }); 
     alert(item); 
     return false; 
    }); 
} 

干杯

+0

对切片的API在读( ):http://api.jquery.com/slice/ –

回答

1

您可以使用切片这样的事情

DEMO

$(function(){ 


     var count = 6; 
     showListItems(0 , count); 

     $('button').click(function() { 
      showListItems(0, ($('ul li:visible').length) + count); 

     }); 

     function showListItems(firstNumber, lastNumber) 
     { 
      $('ul li').slice(firstNumber, lastNumber).fadeIn("slow"); 
     }  


    });​ 
+1

henkieee感谢nidge,我是d完全一样的东西,但我错过了切分数字。非常感激。 –