window.onload = function(){
    var oBtn = document.getElementById("footer");
    var timer;
    var isCom = false;   //定义一个变量
    oBtn.onclick = function () {
        timer = setInterval(function () {
            isCom = true;
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            var speed = Math.ceil(scrollTop / 10);   //scrollTop 的数值越来越大  所以speed发也越来越大  速度越到上面越慢
            document.documentElement.scrollTop -= speed;
            document.body.scrollTop -= speed;
            if (scrollTop <= 0) {
                clearInterval(timer);
            }
        }, 20)
    }

    window.onscroll = function () {
        if (!isCom) {
            clearInterval(timer)
        } else {
            isCom = false;
        }
    }
}