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 />

4. Save this file as parallax.css in the css directory. At this point the page should<br />

appear like this:<br />

The stage area is the ground, the foreground layer is the dark green bushes, the midground<br />

is the light green bushes, and the background slice is the sky and clouds.<br />

What just happened?<br />

You'll also find the images for this example in the img folder <strong>of</strong> the code download<br />

accompanying this book. We have a separate image for each element that we wish to<br />

be part <strong>of</strong> the parallax effect, three in this example, one for the background, one for<br />

the midground, and one for the foreground.<br />

The underlying HTML is also very simple. We just have a separate for each layer <strong>of</strong><br />

the background. In the CSS, each image layer is positioned absolutely so that they overlay<br />

each other.<br />

Time for action – animating the background position<br />

Now for the itself. At the bottom <strong>of</strong> the HTML file, in the empty function as usual,<br />

add the following code:<br />

var bg = $("#background"),<br />

mg = $("#midground"),<br />

fg = $("#foreground");<br />

[ 188 ]

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

Saved successfully!

Ooh no, something went wrong!