设置左右滑动,且滑动到当前位置tabSlide

//滑动
function tabSlide(boxid,listid,previd,nextid,lwidth,cwidth,n,pageNo){
	var box = $("#"+boxid),
		list = $("#"+listid),
		listLen = box.find("li").length,
		prevBtn = $("#"+previd),
		nextBtn = $("#"+nextid),
		nowP = 0,
		pnum = Math.ceil(listLen/n),
		changeValue = true;
	list.css({"width":lwidth*listLen});
       nowP=Math.ceil(pageNo/n)-1;
      list.css({"left":-nowP*cwidth});
	prevBtn.unbind('click').click(function(){
		if(changeValue==true){
			if(nowP>0){
				changeValue=false;
				nowP--;
				list.animate({"left":-nowP*cwidth},500);
				if(nowP == 0){
					prevBtn.addClass('gray');
				}
				nextBtn.removeClass('gray');
				setTimeout(function(){
					changeValue=true;					
				}, 550)					
			}			
		}
	})
	nextBtn.unbind('click').click(function(){
		if(changeValue==true){
			if(nowP<(pnum-1)){
				changeValue=false;
				nowP++;
				if(nowP == (pnum-1)){
					nextBtn.addClass('gray');
				}
				list.animate({"left":-nowP*cwidth},500);
				prevBtn.removeClass('gray');
				setTimeout(function(){
					changeValue=true;					
				}, 550)	
			}			
		}
	})
}


使用:

参数的:标签名都是id
matchBox:ul外层的div,限制了宽高
matchList:ul,设置父级的高,不设置宽,然后overflow: hidden;
matchPrev: 上翻
matchNext:下翻
248:每个li的宽度
1240:5个li的宽度
5: 一次移动5条
self.dLiveNum: 后台返回的数据,取到需要拉取到的当前li的index(例如:当前正在进行的,或者没有进行的则拉取即将开始的)

tabSlide("matchBox", "matchList", "matchPrev", "matchNext", 248, 1240, 5, self.dLiveNum);

猜你喜欢

转载自blog.csdn.net/dxj124/article/details/87880583
今日推荐