我認爲這是一個更完整的答案。它執行以下操作:
- 任何活動計時器都將被清除。
- 所有事件都被清除
- 所有對象的屬性將被清除
- 採用常見的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