Created
August 27, 2021 16:20
-
-
Save MrZyr0/ff631943e0ceb81f1fb5a6eba22b0741 to your computer and use it in GitHub Desktop.
A simple js script to present websites beautifully
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add here all scroll value you want (each scroll steps). Scroll manually and use pageYOffset to setup it | |
// If empty, the script will automaticly scroll by 90% of the window height | |
const scrollOffsets = [] | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function a() { | |
const scrollElementHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, | |
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight) | |
const maxScroll = Window.scrollMaxY || scrollElementHeight - window.innerHeight - 1 | |
for (let index = 0; index < scrollOffsets.length; index++) { | |
await sleep(3000); | |
window.scrollTo({ | |
top: scrollOffsets[index], | |
left: 0, | |
behavior: 'smooth' | |
}) | |
} | |
if (pageYOffset < maxScroll) { | |
for (let index = 0; window.pageYOffset < maxScroll; index++) { | |
await sleep(3000); | |
window.scrollBy({ | |
top: window.innerHeight*0.9, | |
left: 0, | |
behavior: 'smooth' | |
}) | |
} | |
} | |
} | |
a() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment