开发者

Assigning custom starting position on a website

开发者 https://www.devze.com 2023-02-28 23:41 出处:网络
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 ho

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号