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

What just happened? We add a click handler to the at the bottom of the list which drives the functionality of the rest of the behavior. When the is clicked, we cache the selector for the field and obtain the text that was entered into it. [ 145 ] Chapter 6 If the variable holding the text is not empty, we then create a new and . We add the text to the as well and then append the new item to the list. Finally, we apply the highlight effect and empty the field. The pulsate effect The pulsate effect fades the element in and out of view a specified number of times so that the target element appears to pulsate. Like most of the effects we have looked at so far, it is easy to use and requires little or no configuration. Configuration options The pulsate effect also has just two configurable options; these are shown in the following table: Option Default Usage mode "show" Sets whether the target element is shown or hidden when used with the effect() method. Other possible values include hide, toggle, and effect. times 5 Sets the number of times the target element is pulsated. Time for action – making an element pulsate In this example, we'll show a simple time sheet in which rows can be deleted by clicking a link. If a link is clicked, the corresponding row will be pulsated before it is removed. 1. Use the following markup in the template file: Job NumberStart TimeEnd Time Total 054328:008:4343 minutesDelete 056848:4310:211 hour 38 minutesDelete

Extended Animations with jQuery UI 0568410:2113:303 hour 9 minutesDelete 2. Add the code to apply the effect to the closure at the bottom of the page: $(".delete").click(function(e) { e.preventDefault(); var row = $(this).closest("tr"); row.closest("tr").children().css("backgroundColor", "red").effect("pulsate", function() { row.remove(); }); }); 3. Save this file as pulsate.html. Only a couple of styles are required for this example. These should go into a new file: table { border-spacing:0; font:normal 13px "Nimbus Sans L", "Helvetica Neue", "Franklin Gothic Medium", Sans-serif; } th, td { text-align:left; padding-right:20px; } 4. Save this file in the css folder as pulsate.css. 5. Clicking the delete link in any row will apply the pulsate effect and then remove the table row: The previous screenshot shows a single pulsate iteration as it fades out. [ 146 ]

What just happened?<br />

We add a click handler to the at the bottom <strong>of</strong> the list which drives the<br />

functionality <strong>of</strong> the rest <strong>of</strong> the behavior. When the is clicked, we cache the<br />

selector for the field and obtain the text that was entered into it.<br />

[ 145 ]<br />

Chapter 6<br />

If the variable holding the text is not empty, we then create a new and .<br />

We add the text to the as well and then append the new item to the list. Finally,<br />

we apply the highlight effect and empty the field.<br />

The pulsate effect<br />

The pulsate effect fades the element in and out <strong>of</strong> view a specified number <strong>of</strong> times so that<br />

the target element appears to pulsate. Like most <strong>of</strong> the effects we have looked at so far, it is<br />

easy to use and requires little or no configuration.<br />

Configuration options<br />

The pulsate effect also has just two configurable options; these are shown in the<br />

following table:<br />

Option Default Usage<br />

mode "show" Sets whether the target element is shown or hidden when used with the<br />

effect() method. Other possible values include hide, toggle, and<br />

effect.<br />

times 5 Sets the number <strong>of</strong> times the target element is pulsated.<br />

Time for action – making an element pulsate<br />

In this example, we'll show a simple time sheet in which rows can be deleted by clicking<br />

a link. If a link is clicked, the corresponding row will be pulsated before it is removed.<br />

1. Use the following markup in the template file:<br />

<br />

Job NumberStart TimeEnd Time<br />

Total<br />

054328:008:4343<br />

minutesDelete<br />

056848:4310:211 hour 38<br />

minutesDelete

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

Saved successfully!

Ooh no, something went wrong!