I’m developing my first one-page horizontal website using jQuery and the scrollTo plugin. The site has 3 screens and starts centered (showing the middle screen). To accomplish this, the logical approach for me was to make <body> have width:300%;, with each screen having width:33.3333%;. When you click a <a>, jQuery sends you to another screen, going left or right.
This works great, however when I try to resize my window I lose all structure, the widths stop making sense. I would like to know what I can do to fix this, but more importantly I would like to understand why this happens.
Here’s Mr. Fiddle. Resize your window and you’ll see what’s wrong. Thanks!
I re-evaluated this as you mentioned in one of the comments on Luke’s answer that you need to remember where you have been last.
You need to track where you are and then go back to there after re-sizing.
Use code similar to this:
See DEMO
I also cached the body element so you do not have to constantly re-traverse to it when scrolling but that added little performance gain.
As before, remember to unbind the event when you leave the page or you could end up with a memory-leak.
I still haven’t managed to get rid of the lagging re-positioning but that is something to work on after.
Edit
Finally found a way to minimise the lag/flickering on resize.
Use
scrollLeft()instead in the resize method it works better, not perfect/prefect but much much better:Updated DEMO