auto scroll 10px top to bottom every 5 second
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auto Scroll Page</title>
<script>
// Function to scroll the page by 10 pixels
function autoScroll() {
window.scrollBy(0, 10);
}
// Wait for the page to load
window.onload = function() {
// Set interval to call autoScroll every 5000 milliseconds (5 seconds)
setInterval(autoScroll, 5000);
};
</script>
</head>
<body>
<h1>Auto Scroll Demo</h1>
<p>Scroll down to see more content.</p>
<div style="height: 2000px;"> <!-- This div adds enough content to make scrolling necessary -->
<!-- Content goes here -->
</div>
</body>
</html>
auto scroll 10px top to bottom random time
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auto Scroll Page</title>
<script>
// Function to scroll the page by 10 pixels
function autoScroll() {
window.scrollBy(0, 10);
// Call the function again with a random delay between 1 and 5 seconds
let randomDelay = Math.random() * 4000 + 1000;
setTimeout(autoScroll, randomDelay);
}
// Wait for the page to load
window.onload = function() {
// Start the auto scroll with an initial delay of 5 seconds
setTimeout(autoScroll, 5000);
};
</script>
</head>
<body>
<h1>Auto Scroll Demo</h1>
<p>Scroll down to see more content.</p>
<div style="height: 2000px;"> <!-- This div adds enough content to make scrolling necessary -->
<!-- Content goes here -->
</div>
</body>
</html>