zoukankan      html  css  js  c++  java
  • 判断滚动条滚到底部

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

    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){
    //滚动到底部
    }

    });
    });
  • 相关阅读:
    两年来的读书小总结(20112013)
    给无边框窗体添加任务栏右键菜单
    使用 yum 命令安装本地安装QQ
    删除非空目录
    gcc安装
    WIN32::OLE操作之excel
    [题解] 组合数学13题
    [算法] 高斯消元及其应用
    [算法] Lucas 定理
    [算法] 最小费用最大流
  • 原文地址:https://www.cnblogs.com/yuyedaocao/p/9970827.html
Copyright © 2011-2022 走看看