Created
October 29, 2016 16:05
-
-
Save rocka/641b642f7784f5207987c83282fd294b to your computer and use it in GitHub Desktop.
JavaScript smoothly scroll to top
This file contains 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
(function ScrollTop(ms) { | |
ms = ms || 500; | |
let length = pageYOffset; | |
let step = length * 1000 / ms / 60; | |
let inv = setInterval(() => { | |
scroll(pageXOffset, pageYOffset - step); | |
}, 16); | |
setTimeout(() => { | |
clearInterval(inv); | |
},ms); | |
})(500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment