CMSの記事があるとして32件毎に無限スクロール風な動きを実装したいです。
ページネーションはないのでソース的にはリストが300件あれば300件分あるという事です。
下記の記述でやりたい動きは出来ているのですが、これを何件になっても問題ないようにループ処理というか簡潔に記述できないでしょうか?
<script> $(function(){ var itemList = $('.item_list'); itemList.find('li:gt(31)').hide(); var itemOffset = itemList.offset(); var itemH = itemList.height(); var wd = $(window); $(window).scroll(function(){ if(wd.scrollTop() > itemOffset.top + 150) { itemList.find('li:nth-child(n+33):nth-child(-n+64)').fadeIn(); if(wd.scrollTop() > itemOffset.top + itemH + 150) { itemList.find('li:nth-child(n+65):nth-child(-n+96)').fadeIn(); if(wd.scrollTop() > itemOffset.top + itemH + itemH + 150) { itemList.find('li:nth-child(n+97):nth-child(-n+128)').fadeIn(); if(wd.scrollTop() > itemOffset.top + itemH + itemH + itemH + 150) { itemList.find('li:nth-child(n+129):nth-child(-n+160)').fadeIn(); } } } } }); }); </script>
お力添え頂ければ幸いです。
どうぞよろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。