Skip to content

Instantly share code, notes, and snippets.

@skwashd
Created November 12, 2023 04:03
Show Gist options
  • Save skwashd/19e5cec15a717db3abbaec1acaec3462 to your computer and use it in GitHub Desktop.
Save skwashd/19e5cec15a717db3abbaec1acaec3462 to your computer and use it in GitHub Desktop.
Safari doesn't support the behaviour property when calling window.scroll. This prevents smooth scrolling. Copy and paste this code into your JS console to get smooth scrolling. Great for screen capture videos.
const footerHeight = 800;
let pos = 0,
pageHeight = document.body.offsetHeight,
winHeight = window.innerHeight,
maxPos = pageHeight - winHeight - footerHeight;
function scrollWin() {
if (pos >= maxPos) {
console.log(`We're done at ${pos}`);
return; // bailout
}
pos += 20;
window.scroll({
top: pos,
left: 0,
});
setTimeout(scrollWin, 20)
}
// We need time to close the console
setTimeout(scrollWin, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment