我正在使用hoverIntent jQuery plugin代替jQuery的hover()
方法。我希望mouseout事件被自动调用。
使用hover()
时,我可以通过调用mouseout()
触发mouseout事件。使用hoverIntent时,这不起作用。
我也尝试调用命名匿名函数,但是它对我不起作用(我听说较旧的IE不喜欢命名匿名函数)。
Here is an example on jsFiddle.
如果我自动调用mouseout函数,则无法通过hoverIntent调用它。
现在我知道我可以做...
$('something').hoverIntent(function() { }, something);
something();
但是我想知道我想要的东西是否可能?
谢谢
最佳答案
不幸的是,除了命名函数外,没有其他方法,不能与插件的结构无关……它不会以以后可以访问的任何方式存储,只能存储到插件的关闭处。
在这里设置:
$.fn.hoverIntent = function(f, g) {
// default configuration options
var cfg = {
sensitivity: 7,
interval: 100,
timeout: 0
};
// override configuration options with user supplied object
cfg = $.extend(cfg, g ? {
over: f,
out: g
} : f);
...然后所有引用都指向该
cfg
对象,该对象只能在插件内部访问。例如,如果您想更改插件并通过cfg
存储该.data()
对象,则可以这样做,但是无法访问或触发任何一个匿名处理程序。