Auto-scrolling a webpage up and down at random intervals between 5 to 10 seconds using JavaScript.
- getRandomInterval(min, max): This function generates a random interval between the provided minimum and maximum values (in seconds), converting it to milliseconds.
- scrollPage(): The main function that initiates the scrolling.
- scrollHeight: The total scrollable height of the page minus the viewport height.
- scrollAmount: The amount by which the page will scroll in each direction. Adjust this value as needed to control the scroll distance.
- direction: A variable to keep track of the current scroll direction (
'down'or'up').
- performScroll(): This function handles the actual scrolling logic. It uses
window.scrollBywithbehavior: 'smooth'for smooth scrolling. - It alternates the direction of scrolling between down and up.
- It sets a new timeout with a random interval between 5 and 10 seconds before the next scroll.