scroll to top in javascript duration

Solutions on MaxInterview for scroll to top in javascript duration by the best coders in the world

showing results for - "scroll to top in javascript duration"
Jameson
13 Jan 2019
1scrollToPageTopWithSlowAniemation(){ 
2  var scrollToTop = window.setInterval(function() {
3    var pos = window.pageYOffset;
4    if ( pos > 0 ) {
5      window.scrollTo( 0, pos - 20 ); // how far to scroll on each step
6    } else {
7      window.clearInterval( scrollToPageTopWithSlowAniemation );
8    }
9  }, 16);//16 is the duration
10}
11
12just copy and call this scrollToPageTopWithSlowAniemation(); 
13
14
15