Last Updated: February 25, 2016
·
724
· beuretv

Scroll to top page

Controle the speed at ending:

function scTt(){



    var scrolltoTop = setInterval(function(){

        var scrollY;
        scrollY = document.body.scrollTop;
        scrollY = document.documentElement.scrollTop;
        scrollY = window.pageYOffset;

        var n;

        if(scrollY >= 80){

            n = 15; // vitesse du scroll

        }


        //smoot arrivée
        if(scrollY <= 80){

        n = 10;

    }
    //smoot arrivée
    if(scrollY <= 50){

        n = 5;

    }
    //smoot arrivée
    if(scrollY <= 30){

        n = 1;

    }

    var goSub =  n++;


    var substract = parseInt(scrollY)-(goSub);


    window.scrollBy(0,substract);

    window.scrollTo(0,substract);


    if(scrollY == 0){
        clearInterval(scrolltoTop);
        //alert('clear');
    }


    },1);





}