Skip to content

Instantly share code, notes, and snippets.

@toruta39
Created July 16, 2012 04:35
Show Gist options
  • Save toruta39/3120582 to your computer and use it in GitHub Desktop.
Save toruta39/3120582 to your computer and use it in GitHub Desktop.
Scroll page to a certain pos
//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