02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

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.

70<br />

CHAPTER 2 ■ COMMON JQUERY ACTIONS AND METHODS<br />

animation will complete before the second begins; the second will complete before the third begins, <strong>and</strong><br />

so on.<br />

The specialEasing option allows developers to attach different easing styles to each CSS property<br />

being animated.<br />

■ Note specialEasing is a new feature in <strong>jQuery</strong> 1.4 <strong>and</strong> the brainchild of James Padolsey. He posted a great<br />

example available at http://james.padolsey.com/demos/jquery/easing/easing-jq14.html.<br />

.delay()<br />

The .delay() method is new in <strong>jQuery</strong> 1.4 <strong>and</strong> essentially allows developers to pause a script’s execution<br />

for a given number of milliseconds. It provides the ability to run one animation <strong>and</strong> wait for a bit before<br />

starting the next animation.<br />

To slide up the paragraph with ID bar, wait 3 seconds, <strong>and</strong> slide it back down, use the following<br />

code:<br />

$("#bar")<br />

.css({<br />

"background":"yellow",<br />

"border":"1px solid black"<br />

})<br />

.slideUp(1000, function(){<br />

console.log("Animation completed!");<br />

})<br />

.delay(3000)<br />

.slideDown(1000, function(){<br />

console.log("Animation completed!");<br />

});<br />

.stop()<br />

To stop an animation, the .stop() method is used. This method accepts two Boolean argument: one to<br />

determine whether the queue should be cleared <strong>and</strong> another to determine whether the animation<br />

should jump to the end. Both values default to false.<br />

To start an animation, stop the animation, clear the queue, <strong>and</strong> jump to the end after 200 steps, use<br />

the following:<br />

var count = 0; // Keep track of the current step count<br />

$("#bar")<br />

.css({<br />

"background":"yellow",<br />

"border":"1px solid black"<br />

})<br />

.animate({<br />

"width":"500px"

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

Saved successfully!

Ooh no, something went wrong!