发表于: 2020-07-14 20:24:55

1 2526


今日完成:

totlepage:一共的页数。也就是Math.ceil(数据的个数 / 每页显示的个数); 

page:表示第几页。也就是下面的数组1、2、3、4、5… 

current:表示当前的页数。当page==current时,给a一个active类名,标红一下。 

currentHead:将下面的数字显示分为5个一组,及12345一组,678910一组,这里的currentHead就是每组中的第一个数字,

head:表示当前页属于第几组,Math.floor(this.current/5),注意像5,10这样this.current%5==0的,head需要减去1 

这样就能得到currentHead = head*5 + 1;


//跳转到指定页

      gopage: function(page) {

        this.current = page;

        var head = Math.floor(this.current/5);

        var rem = this.current % 5;

        if(rem == 0) {

          head -= 1;

        }

        if(head >= 1) {

          this.currentHead = head * 5 + 1;

        }

        this.currentIndexHead = 6*(page-1)+1;

      },

      //下一页

      next: function(){

        if(this.current < this.totlepage) {

          this.current += 1;

          var head = Math.floor(this.current/5);

          var rem = this.current % 5;

          if(rem == 0) {

            head -= 1;

          }

          if(head >= 1) {

            this.currentHead = head * 5 + 1;

          }

          this.currentIndexHead += 6;

        }

      },

      previous: function(){

        if(this.current > 1) {

          this.current -= 1;

          var head = Math.floor(this.current/5);

          var rem = this.current % 5;

          if(rem == 0) {

            head -= 1;

          }

          if(head >= 1) {

            this.currentHead = head * 5 + 1;

          }

          this.currentIndexHead -= 6;

        }

      }





返回列表 返回列表
评论

    分享到