这一直在困扰着我好几天了。 。 。 所以我有这样的布局jQuery一次显示5个列表
<div class='body1'>
<ul id='list1'>
<li class='heading'>Name</li>
<li>Name 1</li>
<li>Name 2</li>
<li>Name 3</li>
</ul>
</div>
<div class='body1'>
<ul id='list2'>
<li class='heading'>Name</li>
<li>Name 1</li>
<li>Name 2</li>
<li>Name 3</li>
</ul>
</div>
<div class='body1'>
<ul id='list3'>
<li class='heading'>Name</li>
<li>Name 1</li>
<li>Name 2</li>
<li>Name 3</li>
</ul>
</div>
,这是我的功能
function changePage(){
var limit = 5; //number of list to show
var pages = $(".body1");
var pageul = $(".body1 ul");
if ($.cookie('pg') == null || $.cookie('pg') >= pages.length){
$.cookie('pg', 0); // just the cookie to retain current div on display when refresh
}
var c = $.cookie('pg');
$(pages).hide(); // hide all divs
$(pageul).find('li').hide(); // hide all list inside divs
$(pages[c]).fadeIn(2000); //fade in the page with index cookie
$(pages[c]).find('li:lt('+limit+')').fadeIn(2000); //fadein the lists
c++; //increment
$.cookie('pg', c); //then store as cookie
window.setTimeout(changePage, 10000); //run every 10 sec
}
什么即时试图做的是显示在10秒间隔循环的所有div,但如果一个div有超过极限列表然后通过每10秒显示5(限制)来分割列表,并且当到达最后一个时,然后继续循环div。
我在正确的轨道上吗?或者我需要一个不同的方法?
IM相当新的jQuery的所以请多多包涵
'pageul'定义在哪里? – 2013-05-11 13:28:44
哎呀抱歉编辑:D – Cyr 2013-05-11 13:31:01
jQuery本身不支持cookies。你是否在使用外部资源? – 2013-05-11 13:44:36