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

[ 143 ] Chapter 6 The highlight effect The highlight effect is a simple but effective way to draw the visitor's attention to new items that have been added to the page, and is used for this purpose in many of today's leading web-based interfaces. Configuration options There are only two configuration options for the highlight effect; these are listed as follows: Options Default Usage color "#ffff99" Sets the background-color of the element being highlighted. mode "show" Sets whether the effect will be hidden or shown when used with the effect() method. Other possible values include hide, toggle, or effect. Time for action – highlighting elements In this example we'll create a simple todo list, with a series of default items that can be checked off. We can also allow new items to be added to the list and will apply the highlight effect to new items as they are added. 1. Add the following HTML to the of the template file: Todo List Item 1 Item 2 Item 3 Add 2. Add the behavior for our todo list using the following code: $("#add").click(function() { var newItem = $("#new"), text = newItem.val(); if (text) { var li = $(""), label = $("").html( "" + text).appendTo(li);

Extended Animations with jQuery UI } }); li.appendTo("#todo ul").effect("highlight", 2000); newItem.val(""); 3. Save this page as highlight.html. We also need some CSS for this example. In a new file in your text editor add the following code: #todo { width:208px; font:normal 13px "Nimbus Sans L", "Helvetica Neue", "Franklin Gothic Medium", Sans-serif; } #todo ul { padding:0; margin-bottom:30px; } #todo li { list-style-type:none; } #todo label { display:block; border-bottom:1px dotted #000; } li input { position:relative; top:2px; } input { margin-right:10px; } 4. Save this page as highlight.css. 5. When we run the page in a browser, we can add a new item and it will be highlighted briefly as the new item is added to the list: In the previous screenshot we see the fade effect before it fades away from the newly added item. [ 144 ]

[ 143 ]<br />

Chapter 6<br />

The highlight effect<br />

The highlight effect is a simple but effective way to draw the visitor's attention to new items<br />

that have been added to the page, and is used for this purpose in many <strong>of</strong> today's leading<br />

web-based interfaces.<br />

Configuration options<br />

There are only two configuration options for the highlight effect; these are listed as follows:<br />

Options Default Usage<br />

color "#ffff99" Sets the background-color <strong>of</strong> the element being highlighted.<br />

mode "show" Sets whether the effect will be hidden or shown when used with the<br />

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

or effect.<br />

Time for action – highlighting elements<br />

In this example we'll create a simple todo list, with a series <strong>of</strong> default items that can be<br />

checked <strong>of</strong>f. We can also allow new items to be added to the list and will apply the highlight<br />

effect to new items as they are added.<br />

1. Add the following HTML to the <strong>of</strong> the template file:<br />

<br />

Todo List<br />

<br />

Item 1<br />

Item 2<br />

Item 3<br />

<br />

Add<br />

<br />

2. Add the behavior for our todo list using the following code:<br />

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

var newItem = $("#new"),<br />

text = newItem.val();<br />

if (text) {<br />

var li = $(""),<br />

label = $("").html(<br />

"" + text).appendTo(li);

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

Saved successfully!

Ooh no, something went wrong!