I want to create a website scrolled vertically. The problem I have is th开发者_C百科at I want starting point on the website to be on the center. I guess I need to use JS for this, but I don't know how.
Apparently outerHeight
is only supported in Firefox. How about this?
var winWidth = document.body.clientWidth;
var winHeight = document.body.clientHeight;
window.scrollTo(winWidth, winHeight / 2);
This should work on most browsers. window.outerHeight is the height of the entire content of the page. window.scrollTo scrolls the browser to the specified x and y coordinate.
window.scrollTo(0, window.outerHeight / 2);
精彩评论