Last active
March 24, 2020 17:19
-
-
Save alexcmgit/a907b0c60581e3fdf2a9cd22c2005b6e to your computer and use it in GitHub Desktop.
Function to Scroll window || any node to top with behavior smooth
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
function scrollTo(top = 0, left = 0, node = window) { | |
node.scroll({ top, left, behavior: "smooth" }); | |
} | |
//Usage | |
node.onclick = function(){ | |
scrollTo(); | |
} | |
//With custom top, left | |
node.onclick = function(){ | |
scrollTo(100, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment