Smooth Scrolling Using window.scrollBy

I am trying to smoothly scroll the page using setInterval () and window.scrollBy ()

I would use the jQuery animation function, but the animation should be continuous and infinite (the content of the page will be infinite).

The idea is pretty simple:

var x = 1;
var y = 1;

setInterval(function() {
    window.scrollBy(0, x);
}, y);

How to increase the speed of scrolling without creating animation animation?

I have two problems:

  • setInterval () cannot take a value of Y less than 1 (or probably closer to 30, depending on browser restrictions)
  • Increasing the value of X causes animation to revive (due to the fact that pixels are generally skipped)

Here is the script for experimenting with:

http://jsfiddle.net/eoojrqh6/2/

Thank!

+4
source share
2 answers

window.scrollBy window.scroll.

http://jsfiddle.net/peterdotjs/f7yzLzyx/1/

var x = 1; //y-axis pixel displacement
var y = 1; //delay in milliseconds

setInterval(function() {
    window.scroll(0, x);
    x = x + 5; //if you want to increase speed simply increase increment interval
}, y);

y , y x, .

+2

, , , . , , . , , , . , , , , goto, Firefox

JavaScript: %20isScrolling; %20var %20scrolldelay; %20function %20pageScroll() %20% {20window.scrollBy(2,1); %20scrolldelay %20% = 20setTimeout ( 'pageScroll()',. 1); %20isScrolling %20 = %20true; %20} %20if (! isScrolling %20 = %20true) %20 { %20pageScroll(); %20} %20else %20 { %20isScrolling %20 = %20false; %20clearTimeout ( scrolldelay); %20}


Internet Explorer Chrome , %20

javascript: var isScrolling; var scrolldelay; function pageScroll() {window.scrollBy(0,1); scrolldelay = setTimeout ('pageScroll()', 15); isScrolling = true; } if (isScrolling!= true) {pageScroll(); } else {isScrolling = false; clearTimeout (scrolldelay); }

, , ,

0

All Articles