JavaScript 判断滚动条是否滚动到最底部

<!DOCTYPE html><head><meta charset="utf-8"><meta name="renderer" content="webkit"><title>js判断滚动条是否到底部</title><style>    .bottom{...
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<title>js判断滚动条是否到底部</title>
<style>
    .bottom{ 
        width: 500px; 
        height: 50px; 
        position: fixed; 
        left: 50%; 
        margin-left: -250px; 
        top: 50%; 
        background: #f00; 
        color: #fff; 
        line-height: 50px; 
        text-align: center; 
        border-radius: 5px; 
        display: none;
    }
</style>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script>
    var timer;
    $(window).bind('scroll',function(){
        clearTimeout(timer);
        timer = setTimeout(function(){
            if($(window).scrollTop()+$(window).height()==$(document).height()){ 
                alert("已经到底部了");
                $(".bottom").fadeIn();
            }else{
                $(".bottom").fadeOut();
            }
        },300)
    }); 
</script>
</head>
<body>
    <div style="width: 100%; height: 2000px;">
        滚动到底部试试~!
    </div>
    <div class="bottom">滚动条,已经到底部了!</div>
</body>
</html>

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
admin
admin

651 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章