Last Updated: February 25, 2016
·
875
· 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);





}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside