A simple JavaScript program to smoothly scroll a web page with some control variables. Useful for making videos of pages that scroll (social media).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

34 lines
792 B

'use strict';
(async ( ) => {
var topMargin = 0; // set to top margin you want for the page scroller
var scrollSpeed = 2; // number of pixels to scroll per frame
var startDelayMs = 0; // set startup delay in milliseconds
var height = 200000; // set to max distance you want to scroll
var y = topMargin;
var paused = false;
function update ( ) {
try {
if (!paused) {
window.scrollTo(0, y);
y += scrollSpeed;
}
if (y < height) {
window.requestAnimationFrame(update);
}
} catch (error) {
console.log('update has failed', error);
}
}
try {
window.scrollTo(0, y);
window.setTimeout(update, startDelayMs);
} catch (error) {
console.log('scroller has failed', error);
}
})();