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

[ 39 ] Chapter 2 #messageList table { border-collapse:collapse; margin:10px 0; background-color:#666; } #messageList th, #messageList td { width:100px; padding:10px; color:#eee; text-align:left; border-bottom:1px solid #eee; } #messageList td { background-color:#ccc; color:#000; } #messageList th.sub { width:220px; } #messageList th.del { text-align:right; } #messageList table a { padding:0 7px 2px; float:right; background-color:#ea3c37; color:#fff; text-align:center; text-decoration:none; border:1px solid #990000; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; } .confirm { color:#eee; font-size:16px; } .confirm button { margin:0 10px; } .confirm a { font-size:12px; color:#ffcaca; } 4. Save this as fadeTo.css in the css folder. What just happened? The underlying HTML is relatively simple; we have an outer containing within which reside a HTML5 element and a . Each row of the corresponds to a received message. Don't forget to link to the fadeTo.css file in the of the new page, as we have in previous examples. As with previous examples, the CSS we use for this example is purely arbitrary and is used simply to make the example presentable. We use the CSS3 rounded corner style property again, to give a nice effect to the widget. Once again, these styles won't work in IE, but the worst that will happen is that it will have square corners. Time for action – adding the behavior Finally we can add the script that will make it all work. In the empty function at the bottom of the element, add the following: var messageList = document.getElementById("messageList"), messages = $("table", messageList), confirmDiv = $("", { "class": "confirm", text: "Really delete?"

Fading Animations }), remove = $("", { id: "delete", text: "Yes" }).appendTo(confirmDiv), cancel = $("", { href: "#", id: "cancel", text: "Cancel", title: "Cancel" }).appendTo(confirmDiv), deleteRow = function(e) { e.preventDefault(); $(this).closest("tr").fadeTo(400, 0.5, function() { $(this).addClass("pre-delete"); confirmDiv.clone().insertAfter(messages); messages.find("a").unbind(); }); }; messages.find("a").click(deleteRow); $("#delete, #cancel").live("click", function(e) { e.preventDefault(); if (this.id === "delete") { messages.find(".pre-delete").fadeTo(400, 0, function() { $(this).remove(); }); } else { messages.find(".pre-delete").removeClass(" pre-delete").fadeTo(400, 1, function() { var el = $(this); if (el.css("filter")) { el[0].style.removeAttribute("filter");; } }); } $(".confirm", messageList).remove(); messages.find("a").click(deleteRow); }); [ 40 ]

[ 39 ]<br />

Chapter 2<br />

#messageList table {<br />

border-collapse:collapse; margin:10px 0; background-color:#666;<br />

}<br />

#messageList th, #messageList td {<br />

width:100px; padding:10px; color:#eee; text-align:left;<br />

border-bottom:1px solid #eee;<br />

}<br />

#messageList td { background-color:#ccc; color:#000; }<br />

#messageList th.sub { width:220px; }<br />

#messageList th.del { text-align:right; }<br />

#messageList table a {<br />

padding:0 7px 2px; float:right; background-color:#ea3c37;<br />

color:#fff; text-align:center; text-decoration:none;<br />

border:1px solid #990000; -moz-border-radius:5px;<br />

-webkit-border-radius:5px; border-radius:5px;<br />

}<br />

.confirm { color:#eee; font-size:16px; }<br />

.confirm button { margin:0 10px; }<br />

.confirm a { font-size:12px; color:#ffcaca; }<br />

4. Save this as fadeTo.css in the css folder.<br />

What just happened?<br />

The underlying HTML is relatively simple; we have an outer containing within which<br />

reside a HTML5 element and a . Each row <strong>of</strong> the corresponds<br />

to a received message. Don't forget to link to the fadeTo.css file in the <strong>of</strong> the new<br />

page, as we have in previous examples.<br />

As with previous examples, the CSS we use for this example is purely arbitrary and is used<br />

simply to make the example presentable. We use the CSS3 rounded corner style property<br />

again, to give a nice effect to the widget. Once again, these styles won't work in IE, but the<br />

worst that will happen is that it will have square corners.<br />

Time for action – adding the behavior<br />

Finally we can add the script that will make it all work. In the empty function at the bottom<br />

<strong>of</strong> the element, add the following:<br />

var messageList = document.getElementById("messageList"),<br />

messages = $("table", messageList),<br />

confirmDiv = $("", {<br />

"class": "confirm",<br />

text: "Really delete?"

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

Saved successfully!

Ooh no, something went wrong!