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.

}<br />

};<br />

$(config.selector).find("a").css("display", "block");<br />

}<br />

});<br />

});<br />

break;<br />

case "strip":<br />

var counter = 0;<br />

function strip() {<br />

transEls.eq(counter).animate({<br />

height: 0<br />

}, 150, function() {<br />

if (counter === len) {<br />

transOverlay.remove();<br />

$(config.selector).find("a").css("display", "block");<br />

} else {<br />

counter++;<br />

strip();<br />

}<br />

});<br />

}<br />

strip();<br />

What just happened?<br />

Our last function deals with actually running the transitions. In this example, there are<br />

just two different types <strong>of</strong> transitions, but we could easily extend this to add more<br />

transition effects.<br />

[ 131 ]<br />

Chapter 5<br />

This function also requires some variables, so we set these at the start <strong>of</strong> the function for<br />

later use. We cache a reference to the overlay container as we'll be referring to it several<br />

times. We also store the collection <strong>of</strong> transition elements, and the number <strong>of</strong> transition<br />

elements. We subtract 1 from the number <strong>of</strong> children because the figure will be used with<br />

<strong>jQuery</strong>'s eq() method, which is zero-based.<br />

To determine which <strong>of</strong> our transitions to run, we use a JavaScript switch statement and<br />

check the value <strong>of</strong> the config.transitionType property. The first transition is a kind <strong>of</strong><br />

venetian-blind effect. To run this transition, we just animate the width <strong>of</strong> each element to 0<br />

using the <strong>jQuery</strong> each() method. The function we specify as the argument to this method<br />

automatically receives the index <strong>of</strong> the current element, which we access using i.

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

Saved successfully!

Ooh no, something went wrong!