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

} var el = $(this); if (el.css("filter")) { el.css("filter", ""); } }); $(".confirm", messageList).remove(); messages.find("a").click(deleteRow); }); 2. Save the new file as fadeToIE.html in the main project folder. [ 45 ] Chapter 2 What just happened? Let's look at what changed in the new version of this example. The first difference is that in the deleteRow function, we store a reference to the element that we are going to fade in a variable called selector (storing jQuery objects in a variable like this is commonly known as caching a selector). We check for the presence of the ActiveXObject on the window object. This object will only exist in IE and so is a useful thing to check for if we are looking to target just IE. If the object is found, we select the elements within the target row instead of the row itself. If the object is not found, we select the itself (as we did in the previous example). The other changes are in the click handler for the delete and cancel elements. All we do is check for the ActiveXObject again and if found, check each element to find which one is empty. One of the rows will be empty because it is the elements that get removed in IE. The empty row is then removed. We have also added a callback function to the animation when the Cancel link is clicked. When IE animates the elements to half opacity, the clearType effect that IE uses for font-smoothing is removed. This is a consequence of the filter being applied, which is how jQuery sets the opacity in IE. Within the new callback function, we check for the presence of the filter attribute, and if it is found, we set to an empty string to disable it. The text will then return to its anti-aliased state.

Fading Animations When we run the new version of the file in IE we should find now that it works as expected in all current versions. Even though we are fading the individual cells in IE instead of the rows, visually it is the same. Because of the conditional checking we do, this version of the example should continue to work in other browsers such as Firefox, Chrome, or Safari as well. As we can see in the previous screenshot, the fades are now working in IE. However, IE still doesn't like fading the elements. It displays a border between the From and Delete columns, even though these cells do not have a border style set on them. IE8 also loses borders when the element is faded back to full opacity. This is not a problem in IE7, and can be fixed in IE8 by removing the background-color from the elements. Showing and hiding By default, jQuery's show(), hide(), and toggle() methods show or hide the selected element by manipulating its display style property. This is an instantaneous effect and does not constitute an animation. [ 46 ]

Fading <strong>Animation</strong>s<br />

When we run the new version <strong>of</strong> the file in IE we should find now that it works as expected<br />

in all current versions. Even though we are fading the individual cells in IE instead <strong>of</strong> the<br />

rows, visually it is the same. Because <strong>of</strong> the conditional checking we do, this version <strong>of</strong> the<br />

example should continue to work in other browsers such as Firefox, Chrome, or Safari<br />

as well.<br />

As we can see in the previous screenshot, the fades are now working in IE. However, IE still<br />

doesn't like fading the elements. It displays a border between the From and Delete<br />

columns, even though these cells do not have a border style set on them. IE8 also loses<br />

borders when the element is faded back to full opacity. This is not a problem in IE7, and<br />

can be fixed in IE8 by removing the background-color from the elements.<br />

Showing and hiding<br />

By default, <strong>jQuery</strong>'s show(), hide(), and toggle() methods show or hide the selected<br />

element by manipulating its display style property. This is an instantaneous effect and<br />

does not constitute an animation.<br />

[ 46 ]

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

Saved successfully!

Ooh no, something went wrong!