Skip to content

Instantly share code, notes, and snippets.

@CarlLee
Last active December 16, 2015 13:29
Show Gist options
  • Save CarlLee/5442057 to your computer and use it in GitHub Desktop.
Save CarlLee/5442057 to your computer and use it in GitHub Desktop.
scroll to mid of page when load
window.addEventListener('load', function(){
var body = document.body,
html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
console.log(height/2 - window.innerHeight/2);
window.scrollTo(0, height/2 - window.innerHeight/2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment