When the browser opens up my page, the browser should already be in the center of the whole page.
Meaning: I have a horizontal one-page, which instead of starting from the left and going to the right (e.g. this), will start in the middle, and be able to scroll to the content on both the right AND the left.
Here is a visual:
If possible, I'd like to avoid dom-ready scrolling via JavaScript or jQuery (I'm using it for navigational aid and stuff anyways), and use only pure html5/css or at least focusing the screen pre-dom-ready through JavaScript/jQuery.
Two ideas on my part:
a) moving the container to the left e.g. using margin-left:-x
, but that usually cuts it off.
b) moving the screen to the right from the start.
Alas, I have been too unsavvy to achieve this on my own.
p.s. here my jsfiddle for consistency: http://jsfiddle.net/alexdot/2Dse3/
An easy jQuery solution
Solution
If you want to hide data, add
visibility:hidden;
to the elements with a content which should be kept hidden at the start. Execute my page scrolling code, and finally changevisibility:hidden;
tovisibility:visible
.What's going to happen?
visibility:hidden
window.scrollTo(..., ...)
visibility=visible
Fiddle: http://jsfiddle.net/2Dse3/5/
Scrolling code
Scrolling the page to the center cannot be achieved with pure CSS/HTML. This can only be done by using JavaScript. For this simple purpose, I'd rather use native JavaScript than including a JQuery plugin (unnecessary server load).
JavaScript code:
You have to adjust the CSS (see Fiddle):
A final note. What do you expect when the user has disabled JavaScript? Are they allowed to see the contents of the page? If yes, add this:
Otherwise, add
<noscript>JavaScript is required to read this page</noscript>
.What's wrong with DOM-ready?
I'm pretty sure it can't be done with CSS alone.