zoukankan      html  css  js  c++  java
  • 判断用户下拉是否触底

    export default {
      data(){
        return{
          date:[]
        }
      },
      methods:{
        async getInitialUsers(){
          let res = await get_message.get('http://localhost:3000/json')
          this.date.push(res)
          console.log(this.date)
        },
        scroll(){
          window.onscroll = () =>{
            // console.log("滚动条滚动距离",document.documentElement.scrollTop)
            // console.log("窗口可视高度",window.innerHeight)
            // console.log("元素的高度",document.documentElement.offsetHeight)
            let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight  ===  document.documentElement.offsetHeight
            console.log("滑动到最底部",bottomOfWindow)
            if(bottomOfWindow){//用户下拉触底
              setTimeout(()=>{
                this.getInitialUsers() //发送请求ajax获取数据
              },1000)
            }
          }
        }
      },
      mounted(){
        this.getInitialUsers()//页面加载完成,请求一次数据
        this.scroll()//每次用户下拉触底后再次发送ajax请求获取数据
      }
    }
     
    注意:如果无法打印出滚动条滚动距离等等信息。。。(请删除掉css样式 overflow:scroll;)
  • 相关阅读:
    mybatis 使用缓存策略
    mybatis 使用事务处理
    mybatis 使用接口绑定
    mybatis 配置文件全解
    mybatis mapper映射文件全解
    mybatis中使用log4j
    初次使用Mybatis
    Servlet 实现文件上传与下载
    log4j v2版本的配置和使用
    Servlet 转发请求与重定向,以及路径问题
  • 原文地址:https://www.cnblogs.com/tlfe/p/11096984.html
Copyright © 2011-2022 走看看