js判断滚动条是否到底部


<html>

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title>title>
        <script src="">script>
        <style type="text/css">
            * {
                padding: 0px;
                margin: 0px;
            }
            #main {
                width: 100%;
                height: 2000px;
                background: pink;
            }
        style>
        <script type="text/javascript">
            $(window).scroll(function() {  
                var scrollTop = $(this).scrollTop();  
                var docHeight = $(document).height();  
                var windowHeight = $(this).height();
                var scrollHeight=document.body.scrollHeight;
                console.log("scrollTop:"+scrollTop);
                console.log("scrollbottom:"+(docHeight-scrollTop-windowHeight));
                if(scrollTop + windowHeight == docHeight) {    
                    alert("已经到最底部了!");  
                }
            });
        script>
    head>

    <body>
        <div id="main">div>
    body>

html>

你可能感兴趣的:(JavaScript)