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

Create successful ePaper yourself

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

68<br />

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

The .animate() method accepts several arguments in two formats: In the first format, the method is<br />

passed a JSON-formatted set of CSS properties to animate as the first argument, an optional duration in<br />

milliseconds for the second argument, an optional easing formula as the third argument, <strong>and</strong> an<br />

optional callback as the fourth argument. The second format passes a JSON-formatted set of CSS<br />

properties as its first argument <strong>and</strong> a JSON-formatted set of options as its second.<br />

After setting a background <strong>and</strong> border style, to animate the height <strong>and</strong> width of the paragraph<br />

element with ID bar over the span of 5 seconds using the "swing" easing type <strong>and</strong> logging a message<br />

upon completion, you would use the following for the first format:<br />

$("#bar")<br />

.css({<br />

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

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

})<br />

.animate({<br />

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

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

},<br />

5000,<br />

"swing",<br />

function(){<br />

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

});<br />

Upon completion, the paragraph is yellow with a black border <strong>and</strong> has changed its size to match the<br />

parameters passed (see Figure 2-21).<br />

Figure 2-21. The paragraph after animating its height <strong>and</strong> width

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

Saved successfully!

Ooh no, something went wrong!