- İstanbul
Highlights
- Pro
Block or Report
Block or report yanekyuk
Report abuse
Contact GitHub support about this user’s behavior. Learn more about reporting abuse.
Report abusePinned
-
Dead simpe pure JavaScript smooth sc...
Dead simpe pure JavaScript smooth scroll to top 1function scrollToTop () {
2var val = document.body.scrollTop || document.documentElement.scrollTop // THIS ONE IS HOW MUCH THE PAGE IS SCROLLED DOWN
3if (val > 1) { // if (val > 0) also works, BUT SINCE WE TAKE THE SQUARE ROOT OF THE VAL, WHEN THE VAL IS FLOAT, IT NEVERS REACHES TO ZERO (IN THIS CASE IT IS INTEGER)
4window.scrollBy(0, -Math.sqrt(val * 0.125) * 2) // HERE YOU CAN PLAY WITH THE VALUES TO CUSTOMIZE THE SPEED. 0.125 AFFECTS THE SMOOTHNESS, 2 AFFECTS THE OVERALL SPEED
5timeoutForScroll(true, 10) // OF COURSE YOU CAN CHANGE THE VALUE 10 TO CHANGE THE SPEED
Something went wrong, please refresh the page to try again.
If the problem persists, check the GitHub status page or contact support.
If the problem persists, check the GitHub status page or contact support.