Toggling the slide

The final slide method is slideToggle(), which provides rudimentary state-checking in order to determine whether the element should be hidden with slideUp() or shown with slideDown(), and then applies the relevant effect. Like the toggle() method that we looked at earlier, the built-in state checking mechanism is provided as a simple convenience, but there may be situations where we need to provide our own logic.

The slideToggle() method may accept the same arguments as the other slide methods, or an object that makes use of easing. For reference, the usage pattern is as follows:

jQuery(elements).slideToggle([duration], [easing], [callback]);

Get jQuery 1.4 Animation Techniques Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.