简单的翻页组件

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值