Click to See Complete Forum and Search --> : Focus on selected area of page.


Morty500
12-18-2008, 03:33 AM
Hi

Not too sure if this is the right thread to post in but hoping someone can help.

I'm in the middle of creating a large resolution webpage. Basically it's a bit of an arty one that makes use of scrolling to engage the user.

The thing I'm having trouble with (assuming it's possible), I want the webpage to focus on the center when it opens, not at the top left point like most standard websites do.

Is there any way to do this, say, go to a particular set of co-ordinates when the webpage is opened/refreshed?

*Tom*
12-18-2008, 04:33 AM
Hi, you could try

<body onLoad="window.scroll(xcoordinate, ycoordinate);">

or if you want it to sroll to (roughly) the center you could try something like

<body onLoad="window.scroll(document.documentElement.clientWidth/2,document.documentElement.clientHeight/2);">

but reliably getting the document width in all browsers is tricky. Also, I think my example would try to position the center of the document to the top left of the window, so to get it to center the document to the center of the window would be even more difficult to get working in all browsers. Internet Explorer is the worst for this (I think).