开发者

Can I call this anonymous function in jQuery by triggering something?

I'm using the hoverIntent jQuery plugin in place of jQuery's hover() method. I want the mouseout event to be called a开发者_如何转开发utomatically.

When using hover(), I can trigger the mouseout event by calling mouseout(). This doesn't work when using hoverIntent.

I also tried calling a named anonymous function, but it didn't work for me (and I hear older IEs don't like named anonymous functions).

Here is an example on jsFiddle.

If I auto invoke the mouseout function, it can't be called via hoverIntent.

Now I know I could do...

$('something').hoverIntent(function() { }, something);

something();

But I was wondering if what I wanted was possible?

Thanks


Unfortunately there's not a way besides a named function, not with how the plugin is structured...it's not stored in any way that's accessible later, only to the plugin's closure.

It's set here:

$.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);

...then after that all references are to that cfg object which is only accessible inside the plugin. If you wanted to change the plugin and store that cfg object via .data() for example you could, but as-is there's no way to access or trigger either anonymous handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜