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);
}
Written by Valentin Beuret
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#