02.06.2013 Views

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Full Page <strong>Animation</strong>s<br />

What just happened?<br />

The script can be roughly broken into two sections. We have a series <strong>of</strong> variables first,<br />

followed by an each() method that processes the navigation in the header. The very<br />

first thing we do however is to empty the contents <strong>of</strong> the current page. This helps make<br />

our script cleaner, because we don't have to avoid processing the first navigation link in<br />

our each() function.<br />

It also ensures the page continues to work if someone visits, say, page-3.html instead <strong>of</strong><br />

the first page by typing the URL <strong>of</strong> that page directly into the browser's address bar. It resets<br />

the site so that the content <strong>of</strong> the first page is always shown first.<br />

So we first define a series <strong>of</strong> variables. We cache references to the window object, the<br />

top set <strong>of</strong> navigation links, and the content container, and create a new object that we'll<br />

populate later in the script to determine where each page is positioned. We also create an<br />

object containing the width and height <strong>of</strong> the window, again so that we can reference<br />

these properties easily from different points in the script.<br />

We then create a new div element and give it an id attribute for styling purposes. We then<br />

bind an event handler to it which listens for a custom contentLoaded event. <strong>jQuery</strong> easily<br />

allows us to create custom events which can be triggered programmatically by our script<br />

when appropriate.<br />

Within the anonymous handler function, we first define a multiplier that will be used to work<br />

out how big the container for the collection <strong>of</strong> pages should be.<br />

We then append the pages element, which will contain the content <strong>of</strong> each external page,<br />

to the content container on the page, and then add a class name to the content container,<br />

again for styling, but this time for styles that only need to be applied with JavaScript enabled.<br />

Next we set the size <strong>of</strong> the content container so that it can accommodate all <strong>of</strong> the external<br />

page content. We use our screensize object and multiplier to determine its size.<br />

The container needs to be one screen-width wider due to how the external page content<br />

is laid out.<br />

We cater for a little more dynamic styling to the header and footer elements by adding a<br />

class name to them. This allows us to give these two elements fixed positioning so that<br />

they always appear at the top and bottom <strong>of</strong> the viewport and hence remain usable while<br />

we (or our visitors) are navigating around the page. We also add some padding equal to the<br />

height <strong>of</strong> the header so that the content does not slide below it at any point.<br />

[ 196 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!