/    Sign up×
Community /Pin to ProfileBookmark

Focus on selected area of page.

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?

to post a comment
Full-stack Developer

1 Comments(s)

Copy linkTweet thisAlerts:
@_Tom_Dec 18.2008 — 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).
×

Success!

Help @Morty500 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...