简单的翻页组件

来源:互联网 发布:淘宝优惠券领券链接 编辑:程序博客网 时间:2024/05/21 06:57
page_div=function(_pageJson){
this.top=_pageJson.top || 0;
this.pageHeight=_pageJson.pageHeight;
this.pageJson=_pageJson;
this.isLoop=_pageJson.isLoop || false;
this.handle=_pageJson.handle || function(){};
}
page_div.prototype={
init: function( _curPage,totalPage){
this.div=document.getElementById(this.pageJson.divId);
this.lineHeight=(this.pageJson.lineHeight==undefined? this.div.style.lineHeight:(this.div.style.lineHeight=_pageJson.lineHeight));
this.lineSize=this.pageJson.lineSize || Math.ceil(this.pageHeight/this.lineHeight);
this.x=(this.pageJson.x==undefined? this.div.style.left:(this.div.style.left=_pageJson.x));
this.y=(this.pageJson.y==undefined? this.div.style.top:(this.div.style.top=_pageJson.y));
this.w=(this.pageJson.w==undefined? this.div.offsetHeight:(this.div.offsetHeight=_pageJson.w));
this.h=(this.pageJson.h==undefined? this.div.offsetHeight:(this.div.offsetHeight=_pageJson.h));
this.currPage = _curPage;

if(this.pageHeight==undefined){
this.pageHeight=this.lineHeight*this.lineSize;
}
this.totalPage=Math.ceil(this.h/this.pageHeight);
if(this.totalPage <=0)this.totalPage=1;
this.div.offsetTop+=this.pageHeight*(_curPage-1);
if(totalPage!=undefined)this.totalPage=totalPage;
},
turnPage:function(type){
this.currPage+=type;
if(this.isLoop){
if(this.currPage>this.totalPage)this.currPage=1;
else
if(this.currPage<1)this.currPage=this.totalPage;
}else{
if(this.currPage>this.totalPage)this.currPage=this.totalPage;
else
if(this.currPage<1)this.currPage=1;
}
this.div.style.top=(this.top-this.pageHeight*(this.currPage-1))+"px";
this.handle();
}
}
0 0
原创粉丝点击