HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

jQuery UI Effects

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."


1. The effect() Method

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);
});

2. Color Animations

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);

3. Animated Class Transitions

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);
Popular Effects List:
  • 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.

Practical Example: Form Feedback

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);
}
Pro Tip: Always use a moderate speed (400ms to 600ms). Effects that are too fast look robotic, while those that are too slow frustrate the user.

Key Points to Remember

  • jQuery UI enables color animations in the animate() method.
  • The effect() method provides unique motions like shake and explode.
  • Class methods (addClass, removeClass) can now take a duration parameter.
  • Use these effects sparingly to enhance UX without distracting the user.
  • Always provide a callback if you need to perform an action after the animation ends.