博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js判断滚轮是否到达页面的底部
阅读量:7097 次
发布时间:2019-06-28

本文共 2319 字,大约阅读时间需要 7 分钟。

hot3.png

// JavaScript Document
/********************
* 取窗口滚动条高度
******************/
function getScrollTop()
{
    var scrollTop=0;
    if(document.documentElement&&document.documentElement.scrollTop)
    {
        scrollTop=document.documentElement.scrollTop;
    }
    elseif(document.body)
    {
        scrollTop=document.body.scrollTop;
    }
    return scrollTop;
}
 
 
/********************
* 取窗口可视范围的高度
*******************/
function getClientHeight()
{
    var clientHeight=0;
    if(document.body.clientHeight&&document.documentElement.clientHeight)
    {
        var clientHeight =(document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;        
    }
    else
    {
        var clientHeight =(document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;    
    }
    return clientHeight;
}
 
/********************
* 取文档内容实际高度
*******************/
function getScrollHeight()
{
    returnMath.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}
 
function test(){
        if(getScrollTop()+getClientHeight()==getScrollHeight()){
                alert("到达底部");
        }else{
                alert("没有到达底部");
        }
}
 
 
//------------------------判断窗体滚动条到达底部----------------------------
 
function reachBottom(){
        var scrollTop =0;
        var clientHeight =0;
        var scrollHeight =0;
        if(document.documentElement && document.documentElement.scrollTop){
                scrollTop = document.documentElement.scrollTop;
        }elseif(document.body){
        scrollTop = document.body.scrollTop;
        }
        if(document.body.clientHeight && document.documentElement.clientHeight){
                clientHeight =(document.body.clientHeight < document.documentElement.clientHeight)? document.body.clientHeight : document.documentElement.clientHeight;
        }else{
                clientHeight =(document.body.clientHeight > document.documentElement.clientHeight)? document.body.clientHeight : document.documentElement.clientHeight;
        }
        scrollHeight =Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
        if(scrollTop + clientHeight == scrollHeight){
                returntrue;
        }else{
                returnfalse;
        }
}
 
 
 
//-----------------判断DIV滚动条到达底部-----------------------
 function sc(){
           var e=document.getElementById('pop_contenter_id');
            if(e.scrollTop>0){
                        var heigh=e.offsetHeight+e.scrollTop;
                        if(heigh>e.scrollHeight-30){
                            alert('到底了  大概的。');
                    }
                }
}

var s=setInterval("sc('{$url}')",4000);

 

 

 

 

 

 

 

转载于:https://my.oschina.net/kt431128/blog/224735

你可能感兴趣的文章
[Usaco2009 Jan]安全路经Travel BZOJ1576 Dijkstra+树链剖分+线段树
查看>>
CSS3制作下拉菜单
查看>>
从机器学习谈起
查看>>
SpringCloud之Eureka入门使用
查看>>
JS-JavaScript类库整理 [更新中...]
查看>>
分布式缓存的面试题11
查看>>
rep insw的用法小记
查看>>
程序员节诗词
查看>>
git远程仓库
查看>>
mysql之 重建GTID下主从关系
查看>>
Oracle 表空间与数据文件
查看>>
[Java小程序]聊天室——Socket和ServerSocket的使用
查看>>
iOS开发-面试总结(十七)
查看>>
改变注释字体颜色
查看>>
indexOf()、lastIndexOf()
查看>>
HDU2044 一只小蜜蜂...
查看>>
POJ2780 Linearity
查看>>
解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
查看>>
Vue打包npm run build 打包后空白怎么解决?
查看>>
RT1052 BootLoader总结
查看>>