'How to add a timer onto a page scroll

I'm working on building an infinite page-scroll, at least until it reaches the last page. However, it scrolls way to quickly and overloads my web-browser. I wanted to know how I can implement a time-lag on each scroll, something like 1-2 seconds between the scrolls.

Here's what I have developed so far:

var infScroll = setInterval(function () {
                                    var scrollingElement = (document.scrollingElement || document.body);
                                    scrollingElement.scrollTop = scrollingElement.scrollHeight;
                                }, 200);

It works and keeps scrolling down the page, however, how do I set a lag between each scroll?

I have tried updating it with a timer as the following:

function disableScroll() {
    // temporarily disable action
    scrollEnabled = false;

    // set a timer to enable again it 1 second from now
    setTimeout(function() {
        scrollEnabled = true;
    }, 8000);
}
var infScroll = setInterval(function () {
                var scrollingElement = (document.scrollingElement || document.body);
                scrollingElement.scrollTop = scrollingElement.scrollHeight; disableScroll()
                                }, 200);

However, the function won't stop the scroll at all for a few moments.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source