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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ 115 ]<br />

Chapter 5<br />

What just happened?<br />

The HTML could be any simple blog post consisting <strong>of</strong> some text and a couple <strong>of</strong> images. The<br />

points to note are that each image is given an id attribute so that it can be easily referenced,<br />

and that each image is actually the full-sized version <strong>of</strong> the image, scaled down with width<br />

and height attributes.<br />

The styles used are purely to lay out the example; very little <strong>of</strong> the code is actually required<br />

to make the example work. The expander-wrapper styles are needed to position the<br />

overlaid images correctly, but other than that the styling is purely arbitrary.<br />

We're floating the second image to the right. Again this isn't strictly necessary; it's used just<br />

to make the example a little more interesting.<br />

Time for action – defining the full and small sizes <strong>of</strong> the images<br />

First we need to specify the full and small sizes <strong>of</strong> each image:<br />

var dims = {<br />

image1: {<br />

small: { width: 150, height: 100 },<br />

big: { width: 600, height: 400 }<br />

},<br />

image2: {<br />

small: { width: 100, height: 100 },<br />

big: { width: 400, height: 400 }<br />

}<br />

},<br />

webkit = ($("body").css("-webkit-appearance") !== "" && $("body").<br />

css("-webkit-appearance") !== undefined) ? true : false;<br />

What just happened?<br />

We create an object which itself contains properties matching each image's filename.<br />

Each property contains another nested object which has small and big properties and<br />

the relevant integers as values. This is a convenient way to store structured information<br />

that can easily be accessed at different points in our script.<br />

We also create a variable called webkit. There is a slight bug in how images floated to the<br />

right are treated in Webkit-based browsers such as Safari or Chrome. This variable will hold<br />

a Boolean that will indicate whether Webkit is in use.<br />

A test is performed which tries to read the -webkit-appearance CSS property. In Webkit<br />

browsers, the test will return none as the property is not set, but other browsers will either<br />

return an empty string or the value undefined.

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

Saved successfully!

Ooh no, something went wrong!