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.

Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />

2. Now add the following code to the empty closure at the bottom <strong>of</strong> the template file:<br />

$("#submit").click(function(e) {<br />

e.preventDefault();<br />

$("input").each(function(i, val) {<br />

if (!$(this).val()) {<br />

$(this).css("border", "1px solid red").effect("shake", {<br />

distance: 5 }, 100);<br />

}<br />

});<br />

});<br />

3. Save this file as shake.html. We also need a basic stylesheet for this example. Add<br />

the following CSS to a new file:<br />

form {<br />

width:145px; padding:20px; margin:auto; border:1px solid #000;<br />

font:normal 13px "Nimbus Sans L", "Helvetica Neue", "Franklin<br />

Gothic Medium", Sans-serif;<br />

}<br />

h2 { font-size:14px; margin-top:0; }<br />

input { display:block; margin-bottom:10px; border:1px solid #000;<br />

}<br />

4. Save this file as shake.css.<br />

5. If we run the page in a browser and click the without completing either<br />

<strong>of</strong> the fields, both fields will have their borders set to red and will shake<br />

from side to side:<br />

[ 148 ]

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

Saved successfully!

Ooh no, something went wrong!