While core jQuery can handle basic fading and sliding, jQuery UI adds a massive library of **advanced animations and transitions**. These include the ability to animate colors, add motion to CSS class changes, and use unique effects like "Explode" or "Shake."
The effect() method is the gateway to dozens of new animations. It takes the
name of the effect and an optional duration.
// Shake an element to indicate an error
$("#login-btn").click(function() {
$("#password-box").effect("shake", { times: 3, distance: 10 }, 500);
});
// Explode an element
$("#trash-icon").click(function() {
$(this).effect("explode", 1000);
});
One of the biggest limitations of standard jQuery is that it cannot animate colors
(background-color, border-color, etc.). **jQuery UI fixes this automatically.** once the
library is loaded, you can use the standard animate() method on colors.
// This won't work in core jQuery, but DOES work in jQuery UI:
$("#box").animate({
backgroundColor: "#aa0000",
color: "#fff",
width: 500
}, 1000);
In standard jQuery, addClass() happens instantly. With jQuery UI, you can
specify a duration to make the transition smooth.
// Transition to a new CSS state over 1 second
$("#target").addClass("new-style", 1000);
// Toggle classes with motion
$("#menu").toggleClass("active", 500);
blind / clip — Reveal like a window shade.bounce / pulsate — Attention-grabbing motion.fold / puff — Geometric transitions.highlight — Briefly changes background to yellow then fades out.
Using highlight and shake provides excellent visual feedback to
the user during form validation.
if (inputVal === "") {
// Shake error and highlight field
$("#input").effect("shake").effect("highlight", {color: "#ff0000"}, 2000);
}
animate()
method.