Created
August 25, 2011 17:12
-
-
Save mpezzi/1171181 to your computer and use it in GitHub Desktop.
jQuery Delayed Hide Plugin
This file contains hidden or 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 Delayed Hide Plugin by M. Pezzi | |
* Version: 1.0 (08/25/11) | |
* https://gist.github.com/1171181 | |
* Dual licensed under the MIT and GPL licences: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
* Requires: jQuery v1.4.2 or later | |
*/ | |
(function($){ | |
$.fn.delayedHide = function(options) { | |
return this.each(function(){ | |
var self = $(this), o = $.extend({}, $.fn.delayedHide.defaults, options), delay, | |
$close = $('<div class="close">Close</div>').bind('click', { message: self }, close); | |
// Append close markup, start delay hide. | |
o.close && self.append($close); | |
o.delay && delayStart(); | |
// If a user hovers, cancel the delay. | |
self.bind('mouseover', function(){ | |
clearTimeout(delay); | |
}); | |
function delayStart() { | |
delay = setTimeout(function(){ | |
close(); | |
}, o.delay); | |
} | |
function delayStop() { | |
clearTimeout(delay); | |
} | |
function hide() { | |
self.slideUp(o.animateDuration, o.animateCallback); | |
} | |
function close(e) { | |
delayStop(); | |
hide(); | |
} | |
}); | |
}; | |
$.fn.delayedHide.defaults = { | |
delay: 5000, | |
close: true, | |
animateDuration: 500, | |
animateCallback: function() { } | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment