Created
July 16, 2012 04:35
-
-
Save toruta39/3120582 to your computer and use it in GitHub Desktop.
Scroll page to a certain pos
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
//Since in Chrome, document.body.scrollTop reflects the scroll distance, | |
//while in IE9 and Firefox, document.documentElement.scrollTop does. | |
//So this will work in either of the 3 browsers to scroll to the pos you want. | |
function scrollTo(pos) { | |
if(document.body.scrollTop){ | |
document.body.scrollTop = pos; | |
} else if(document.documentElement.scrollTop){ | |
document.documentElement.scrollTop = pos; | |
} else { | |
document.body.scrollTop = document.documentElement.scrollTop = pos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment