• 判断滚动条滚到底部


    原理:文档高度 = 视口高度 + 滚动条高度

    1.若是一整个浏览窗口的滚动条:

    $(window).scroll(function () {
    var documentHeight = $(document).height();//1188
    var windowHeight = $(window).height();//706
    var scrollTop = $(document).scrollTop();//482
    var sh = windowHeight + scrollTop ;
    console.log("sh="+sh+"documentHeight="+documentHeight);
        if(windowHeight+scrollTop ==  documentHeight){
    //滚动到底部
    }
    });
    或者
    $(document).scroll(function () {
    var documentHeight = $(document).height();//1188
    var windowHeight = $(window).height();//706
    var scrollTop = $(document).scrollTop();//482
    var sh = windowHeight + scrollTop ;
    console.log("sh="+sh+"documentHeight="+documentHeight);
        if(windowHeight+scrollTop ==  documentHeight){
    //滚动到底部
    }

    });
    2.若是某个div的滚动条:
    $(document).ready(function () {
    $(".tongModalBox").scroll(function () {
    var documentHeight = $(this).prop('scrollHeight');//或$(this)[0].scrollHeight
    var windowHeight = $(this).height();
    var scrollTop = $(this).scrollTop();
    var sh = windowHeight + scrollTop ;
    console.log("sh="+sh+"documentHeight="+documentHeight);
            if(windowHeight+scrollTop ==  documentHeight){
    //滚动到底部
    }

    });
    });
  • 相关阅读:
    前端之CSS:属性操作2
    前端之CSS:属性操作1
    前端之CSS:CSS选择器
    前端之HTML:表单操作
    前端之HTML:HTML
    SQLAlchemy的使用(SQLAlchemy 是一种对象关系映射模型(Object Relational Mapper), 简称ORM。)
    IO多路复用
    协程
    线程的那些事儿
    并发编程的那些事儿(四)
  • 原文地址:https://www.cnblogs.com/yuyedaocao/p/9970827.html
Copyright © 2020-2023  润新知