Skip to content

Instantly share code, notes, and snippets.

@plutochill
Created September 15, 2013 01:26
Show Gist options
  • Save plutochill/6567296 to your computer and use it in GitHub Desktop.
Save plutochill/6567296 to your computer and use it in GitHub Desktop.
让鼠标经过事件和延时分离的出来,延时以及延迟的清除都已经由此方法解决了
(function($){
$.fn.hoverDelay = function(options){
var defaults = {
hoverDuring: 200,
outDuring: 200,
hoverEvent: function(){
$.noop();
},
outEvent: function(){
$.noop();
}
};
var sets = $.extend(defaults,options || {});
var hoverTimer, outTimer;
return $(this).each(function(){
$(this).hover(function(){
clearTimeout(outTimer);
hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
},function(){
clearTimeout(hoverTimer);
outTimer = setTimeout(sets.outEvent, sets.outDuring);
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment