我认为这是一个更完整的答案。它执行以下操作:
- 任何活动计时器都将被清除。
- 所有事件都被清除
- 所有对象的属性将被清除
- 采用常见的jQuery的语法和看起来像hoverIntent
代码的本地部分:
(function($) {
if (typeof $.fn.hoverIntent === 'undefined')
return;
var rawIntent = $.fn.hoverIntent;
$.fn.hoverIntent = function(handlerIn,handlerOut,selector)
{
// If called with empty parameter list, disable hoverintent.
if (typeof handlerIn === 'undefined')
{
// Destroy the time if it is present.
if (typeof this.hoverIntent_t !== 'undefined')
{
this.hoverIntent_t = clearTimeout(this.hoverIntent_t);
}
// Cleanup all hoverIntent properties on the object.
delete this.hoverIntent_t;
delete this.hoverIntent_s;
// Unbind all of the hoverIntent event handlers.
this.off('mousemove.hoverIntent,mouseenter.hoverIntent,mouseleave.hoverIntent');
return this;
}
return rawIntent.apply(this, arguments);
};
})(jQuery);
来源
2013-06-04 15:00:13
rds
你可以尝试有两个类,并将一个事件绑定到每个事件。然后,您只需添加/删除相关元素上的正确类。 – Jerome