Skip to content

Instantly share code, notes, and snippets.

@mathiasbynens
Created September 2, 2010 14:56
Show Gist options
  • Save mathiasbynens/562398 to your computer and use it in GitHub Desktop.
Save mathiasbynens/562398 to your computer and use it in GitHub Desktop.
jQuery toggleFade()
jQuery.fn.toggleFade = function(speed, callback) {
speed = ~~speed || 400;
callback = callback || jQuery.noop;
return this.each(function() {
var $this = jQuery(this);
$this[$this.is(':hidden') ? 'fadeIn' : 'fadeOut'](speed, callback);
});
};
@mathiasbynens
Copy link
Author

Cool, a fadeToggle method has been introduced in jQuery 1.4.4. This snippet can still be used for earlier jQuery releases, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment