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.

Using the second format, the code would change as follows:<br />

$("#bar")<br />

.css({<br />

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

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

})<br />

.animate({<br />

"width":"500px",<br />

"height":"100px"<br />

},<br />

{<br />

"duration":5000,<br />

"easing":"swing",<br />

"complete":function(){<br />

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

}<br />

});<br />

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

This produces an identical result. The second format of .animate() provides for additional options<br />

as well. To complete the same action using all available options, your code might look like this:<br />

$("#bar")<br />

.css({<br />

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

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

})<br />

.animate({<br />

"width":"500px",<br />

"height":"100px"<br />

},<br />

{<br />

"duration":5000,<br />

"easing":"swing",<br />

"complete":function(){<br />

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

},<br />

"step":function(){<br />

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

},<br />

"queue":true,<br />

"specialEasing":{<br />

"width":"linear"<br />

}<br />

});<br />

The step option allows developers to create a callback function to be fired after each step of the<br />

animation. This is each time the property is adjusted, so the preceding example ends up outputting quite<br />

a few log messages of "Step completed!".<br />

The queue option tells the animation whether or not it should be added to the current queue, that is,<br />

the order in which animations have been called. If multiple animations are called <strong>and</strong> queued, the first<br />

69

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

Saved successfully!

Ooh no, something went wrong!