jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

[ 85 ] Chapter 4 } h2 { margin:0; padding:7px 0 7px 14px; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px; color:#fff; background-image:-moz-linear-gradient(0% 22px 90deg, #222, #999); background-image:-webkit-gradient(linear, 0% 0%, 0% 50%, from(#999), to(#222)); } #basketToggle { position:absolute; right:14px; top:10px; color:#ccc; } #basketToggle:hover { color:#fff; } #basketToggle:active { color:#ddd; } #basketToggle:focus { outline:none; color:#ddd; } table { width:860px; margin:auto; border-collapse:collapse; border-spacing:0; } td, th { padding:20px 10px; border:1px solid #000; } th { border-top:none; } #contents { display:none; } #contents table { background-color:#fff; } .summary td, th { background-color:#ccc; background-image:-moz-linear-gradient(0% 40% 90deg, #ccc, #fff); background-image:-webkit-gradient(linear, 0% 0%, 0% 40%, from(#fff), to(#ccc)); } .qty, .desc { width:50px; text-align:left; } .qty, #total .subtotal { border-left:none; } .subtotal, .total { width:112px; } .subtotal { text-align:right; border-left:0; } .total { text-align:left; border-right:none; } .vat .subtotal, .vat .total { border-bottom:none; } #total .subtotal, #total .total { border-bottom:none; } #total td { color:#fff; border:1px solid #fff; } #total .total { border-right:none; font-weight:bold; } .summary .subtotal, #total .subtotal, .desc { width:auto; } #total .subtotal, #total .total { -moz-border-radius:0 0 7px 7px; -webkit-border-radius-bottom-left:7px; -webkit-border-radius-bottom-right:7px; border-radius:0 0 7px 7px; background-image:-moz-linear-gradient(0% 70% 90deg, #222, #999); background-image:-webkit-gradient(linear, 0% 0%, 0% 70%, from(#999), to(#222)); }

Sliding Animations 4. Save this in the css folder as slideToggle.css and link to the file from the of the page we just created. 5. For the final part of the example we can add the script that will toggle the visibility of the contents table. Add the following code to the bottom of the HTML page: var toggler = $("#basketToggle"), basketArea = $("#contents"), newText = ["", "basket", "contents"]; toggler.click(function(e) { } }); e.preventDefault(); if (!basketArea.is(":animated")) { basketArea.slideToggle("slow", function(){ toggler.text(function(i, text) { if (basketArea.is(":visible")) { newText[0] = "Hide"; } else { newText[0] = "Show"; } toggler.text(newText.join(" ")); }); }); 6. Run the page in your browser now. You should find that you can open or close the contents section of the basket area by clicking the link in the top-right of the container. The basket area should expand like this: [ 86 ]

Sliding <strong>Animation</strong>s<br />

4. Save this in the css folder as slideToggle.css and link to the file from the<br />

<strong>of</strong> the page we just created.<br />

5. For the final part <strong>of</strong> the example we can add the script that will toggle the visibility<br />

<strong>of</strong> the contents table. Add the following code to the bottom <strong>of</strong> the HTML page:<br />

var toggler = $("#basketToggle"),<br />

basketArea = $("#contents"),<br />

newText = ["", "basket", "contents"];<br />

toggler.click(function(e) {<br />

}<br />

});<br />

e.preventDefault();<br />

if (!basketArea.is(":animated")) {<br />

basketArea.slideToggle("slow", function(){<br />

toggler.text(function(i, text) {<br />

if (basketArea.is(":visible")) {<br />

newText[0] = "Hide";<br />

} else {<br />

newText[0] = "Show";<br />

}<br />

toggler.text(newText.join(" "));<br />

});<br />

});<br />

6. Run the page in your browser now. You should find that you can open or close<br />

the contents section <strong>of</strong> the basket area by clicking the link in the top-right <strong>of</strong> the<br />

container. The basket area should expand like this:<br />

[ 86 ]

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

Saved successfully!

Ooh no, something went wrong!