zoukankan      html  css  js  c++  java
  • 页面滚动到底部加载更多分页

    
    
    // 通常写法
    window.onscroll = function (e) { /* 判断是否滚到最下面 */ /* 如果已经滚到最下面则执行某个操作 */ var e =e || window.event; // 为了兼容谷歌和火狐 document.body.scrollTop是谷歌上的 /* 滚动条的垂直位置 */ var scrolltop = document.documentElement.scrollTop||document.body.scrollTop; /* 整个页面的正文高度 */ var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight; /* 可见区域高度 */ var clientHeight = document.documentElement.clientHeight||document.body.clientHeight; /* 当scrolltop加clientHeight 等于scrollHeight */ if(scrollHeight === (scrolltop+clientHeight)){ loadmore(); } }

    // 特定区域元素
    handleScroll() {
    // -160 去掉非可视List内容区高度 var scrollTop = this.answerRef.scrollTop; // 滚动条溢出高度 var windowHeight = (document.documentElement.clientHeight - 160) || (document.body.clientHeight - 160); // 可视窗口高度 var scrollHeight = this.answerRef.scrollHeight; // 滚动内容高度 // console.log(scrollTop, windowHeight, scrollHeight) if (scrollTop + windowHeight == scrollHeight) {this.pageInfo.pageNum++; return false; } },

    this.$nextTick(() => {
    this.answerRef = this.$refs.answer;
    window.addEventListener("scroll", this.handleScroll, true);
    })
     
  • 相关阅读:
    HTTP以及TCP协议
    分布式理论
    JAVA基础面试题
    JAVA基础面试题
    vue 中百度富文本初始化内容加载失败(编辑操作某列数据时,富文本中内容偶尔会为空)
    CodeMirror的使用方法
    JSON格式化,JSON.stringify()的用法
    promise与await的用法
    服务器端node.js
    数组扁平化
  • 原文地址:https://www.cnblogs.com/jiaqi1719/p/13728153.html
Copyright © 2011-2022 走看看