js两种请求,点击加载和下拉加载,为什么下拉无法计数

第一种

var page =0;
$(window).scroll(function(){
     if($(window).scrollTop()== $(document).height() - $(window).height()){
       page++;
       getmoretopic(page);
     }
});

第二种

var page =0;
$('#getmorebtn').click(function(){
     page++;
     getmoretopic(page);
});

为什么第一种page一直都是1,不会递增。第二种page可以递增。

如果要限制2次请求的间隔时间,应该怎么配置

我测试 if($(window).scrollTop()== $(document).height() - $(window).height())这个判断没问题啊。
加了请求的间隔时间的代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title> 页面名称 </title>
<style type="text/css">
.c {
    height: 500px;
    border: 5px solid #999;
    font-size: 40px;
}
</style>
</head>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<body>

<div class="c">a</div>
<div class="c">b</div>
<div class="c">c</div>
<script type="text/javascript">
var page =0;
var interval = 5000;//间隔时间
var time = new Date().getTime()-interval;
var timer;
$(window).scroll(function(){
    if($(window).scrollTop() >= $(document).height() - $(window).height()){
        var t = new Date().getTime();
        clearTimeout(timer);
        timer = setTimeout(function(){
            time = new Date().getTime();
            page++;
            getmoretopic(page);
        }, interval-(t-time));
    }
});

function getmoretopic(page) {
    $("body").append('<div class="c">'+page+'</div>')
}

</script>

</body>
</html>