js scroll函数

 $(function () {

        $(".sticky").hide();

        var top = $(window).scrollTop();

        if (top >= 100) {
            $(".sticky").show();
        }
        else {
            $(".sticky").hide();
        }
        
        $(window).scroll(function () {
            var scrollTop = $(this).scrollTop();
            if (scrollTop >= 100) {
                $(".sticky").show();
            }
            else {
                $(".sticky").hide();
            }
        });

    });


    function backTop() {

        $('body,html').animate({ scrollTop: 0 }, 1000);
    }

 javascript onscroll函数


window.onload = function () {
    var topbtn = document.getElementById("btn");
    var timer = null;
    var pagelookheight = document.documentElement.clientHeight;

    window.onscroll = function(){

        var backtop = document.body.scrollTop;
        if(backtop >= pagelookheight){
            topbtn.style.display = "block";
        }else{
            topbtn.style.display = "none";
        }
    }

    topbtn.onclick = function () {

        timer = setInterval(function () {
            var backtop = document.body.scrollTop;
            var speedtop = backtop/5;
            document.body.scrollTop = backtop -speedtop;
            if(backtop ==0){
                clearInterval(timer);
            }
        }, 30);
    }
}

 

posted @ 2015-05-12 12:23  大空白纸  阅读(929)  评论(0编辑  收藏  举报