Welcome 微信登录

首页 / 脚本样式 / JavaScript / JS实现当前页居中分页效果的方法

本文实例讲述了JS实现当前页居中分页效果的方法。分享给大家供大家参考。具体实现方法如下:
function show_page(cur_pc){var cp=cur_pc;//curent page countvar tp=this.p;//total page countvar sp=this.pc;//show page countvar bp;//begin page countvar ep;//end page countif(sp%2==0) sp=sp+1; //this process need an odd numbervar dp=Math.floor(sp/2); //each side count to showvar dif=tp-sp;//check weather it have enough page to make mid-showvar f=cp-dp; //to check weather it has enough page to make mid-show from the beginvar g=tp-(cp+dp); //to check weather it has enough page to make mid-show from the endif(sp && dif>=0){if(g>0){if(f>0){ bp=f; ep=cp+dp; }else{ bp=1; ep=2*dp+1; }}else{ bp=tp-2*dp; ep=tp; }}else{ bp=1; ep=tp; }var buf=[];for(var i=bp;i<=ep;i++){if(i==cur_pc){buf.push("<a href="javascript:;" class="current">",i,"</a>");}else{buf.push("<a href="javascript:;" class="normal">",i,"</a>");}}document.write(buf);}
运行效果如下图所示:

希望本文所述对大家的javascript程序设计有所帮助。