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.

Managing <strong>Animation</strong>s<br />

3. Now change the script at the bottom <strong>of</strong> the page to this:<br />

<br />

(function($){<br />

function changeColor(element, newColor) {<br />

}<br />

$("").css("backgroundColor",<br />

newColor).appendTo(element).fadeIn(500, function(){<br />

});<br />

element.dequeue();<br />

var fader = $("#fader");<br />

var newQ = [<br />

function() { changeColor(fader, "yellow") },<br />

function() { changeColor(fader, "orange") },<br />

function() { changeColor(fader, "green") },<br />

function() { changeColor(fader, "red") },<br />

function() { changeColor(fader, "blue") },<br />

function() { changeColor(fader, "purple") }<br />

];<br />

$("#fader").fadeOut(function() {<br />

//replace queue<br />

$(this).queue(newQ);<br />

}).fadeIn().fadeOut().fadeIn();<br />

})(<strong>jQuery</strong>);<br />

<br />

4. Save the file as queueReplace.html.<br />

What just happened?<br />

First we define a single function which accepts two arguments. The first is a <strong>jQuery</strong> object<br />

referring to the animated element and the second is a new color.<br />

We then create a new element, set its background-color to the color passed into<br />

the function, append it to the element passed in to the function, and then fade it into view.<br />

[ 64 ]

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

Saved successfully!

Ooh no, something went wrong!