zoukankan      html  css  js  c++  java
  • vue 滚动加载

    <template>
      <div class="wraper" @scroll="onScroll($event)">
        <div class="item" v-for="item in items">
          {{item}}
        </div>
      </div>
    </template>
    
    <script>
    export default {
      data () {
        return {
          items:[],
          pgSize:36,
          rawItems:[],
          pgNo:1
        }
      },
     
      ready () {
        for(var i=0;i<=1000;i++){
          this.rawItems.push(i)
        }
        this.changePgItems()
      },
      methods:{
        onScroll(event){
          var offsetHeight = event.currentTarget.offsetHeight,
          scrollHeight = event.target.scrollHeight,
          scrollTop = event.target.scrollTop,
          scrollBottom = offsetHeight + scrollTop
          if(scrollTop===0)
          {
            if(this.pgNo===1)
            {
              return
            }
            this.pgNo--
            this.changePgItems()
            event.target.scrollTop=offsetHeight-1
          }
          if(scrollBottom===scrollHeight || scrollBottom===scrollHeight+2)
          {
            if(this.pgNo==Math.ceil(this.rawItems.length/this.pgSize))
            {
              return
            }
            this.pgNo++
            this.changePgItems()
            event.target.scrollTop=1
          }
        },
        changePgItems(){
          var start = (this.pgNo-1) * this.pgSize,
          items = this.rawItems.slice(start,this.pgSize+((this.pgNo-1)*this.pgSize))
          this.items = items
        }
      }
    }
    
    
    </script>
    
    <style lang="less">
    
    .wraper{
      border:1px solid red;
      height:100vh;
      overflow-y: auto;
      box-sizing: border-box;
    
    
      .item{
        height: 30px;
        border-bottom: 1px solid #ccc;
      }
    }
    </style>
    

      

  • 相关阅读:
    hdu1754 I Hate It
    51nod 1174 1174 区间中最大的数
    51nod1305 Pairwise Sum and Divide
    51nod 1622 集合对[算法马拉松19 C]
    51nod1265 四点共面
    51nod 1244 莫比乌斯函数之和
    51nod 1240 莫比乌斯函数
    51nod 1113 矩阵快速幂
    51nod 1264 线段相交(几何)
    51nod 1412 AVL树的种类(dp)
  • 原文地址:https://www.cnblogs.com/zyip/p/5907546.html
Copyright © 2011-2022 走看看