Created
September 2, 2010 14:56
-
-
Save mathiasbynens/562398 to your computer and use it in GitHub Desktop.
jQuery toggleFade()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, a
fadeToggle
method has been introduced in jQuery 1.4.4. This snippet can still be used for earlier jQuery releases, though.