O'Reilly logo

Mastering jQuery by Alex Libby

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating custom effects

If you've spent any time applying effects to animated elements, then you will very likely have used .animate(), or one of the shortcut methods, such as .fadeIn(), .show(), or .slideUp(). All of them follow a similar format, where we need to provide at least a duration, type of easing, and potentially a callback function to either perform a task when the animation has completed, or log something to the console to this effect.

All too often though, we may decide to stick with the standard values such as slow, fast, or perhaps a numerical value such as 500:

$("button").click(function() {
  $("p").slideToggle("slow");
});

There is absolutely nothing wrong with using this approach - except, it's very boring, and only using a fraction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required