jQuery – 鼠标经过(hover)事件的延时处理
(function($){
$.fn.hoverDelay = function(options){
var defaults = {
hoverDuring: 1000,
outDuring: 0,
hoverEvent: function(){
$.noop();
},
outEvent: function(){
$.noop();
}
};
var sets = $.extend(defaults,options || {});
return $(this).each(function(){
var that = this;
var hoverTimer, outTimer;
$(this).hover(
function(){
clearTimeout(outTimer);
hoverTimer = setTimeout(
function(){sets.hoverEvent.apply(that)},
sets.hoverDuring
);
},
function(){
clearTimeout(hoverTimer);
outTimer = setTimeout(
function(){sets.outEvent.apply(that)},
sets.outDuring
);
}
);
});
}
})(jQuery);
实现
$("#test").hoverDelay({ hoverEvent: function(){ alert("经过我!"); } });