13

I'm using Brian Cherne's hoverIntent.js plugin for a project. It's a great plugin but it seems to be broken in jQuery 1.7.1.

I'm trying to debug it but I'm not the most ace javascripter out there. Can anyone tell me what I might need to look for in his code to fix the following error message:

Uncaught TypeError: Cannot call method 'apply' of undefined

That's what my Chrome console tells me. I'm just not sure what to change.

There is the following line of code in the plugin which contains apply in the string

return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};

EDIT

I should post the link to Brian's full commented code. It's here: http://cherne.net/brian/resources/jquery.hoverIntent.js

EDIT 2

My script is as follows

//#nav-main dropdown effects                
$('#nav-main ul li').hoverIntent(function () {
   $(this).find('.dropdown').stop(true,true).slideToggle('500');
});
6
  • thank you for all the error messages. but basically we need your script code
    – noob
    Commented Dec 4, 2011 at 9:59
  • @micha - edited the question to include it
    – Brian
    Commented Dec 4, 2011 at 10:01
  • It's not the same. hoverIntent prevents this effect from happening (dreamstarstudios.com/screencasts/2011-12-04_0509.swf). Without hoverIntent the dropdowns (since there are many of them) rapidly queue as you hover across. If there were ONE dropdown then your suggestion would be good, but with many, hoverIntent is better.
    – Brian
    Commented Dec 4, 2011 at 10:10
  • @micha watch the video to see the issue
    – Brian
    Commented Dec 4, 2011 at 10:11
  • That works, thanks! You can post as an answer if you want the reputation for answering it.
    – Brian
    Commented Dec 4, 2011 at 10:24

3 Answers 3

28

Basically hoverIntent requires two functions or one object.

If you put in just one function, it will try to use your function as object and you can't apply a function! So use:

$('#nav-main ul li').hoverIntent(function () {
    $(this).find('.dropdown').stop(true,true).slideToggle('500');
}, function(){});
1
  • 4
    There's nothing like modesty... :)
    – Andreas
    Commented Dec 4, 2011 at 10:47
2

If you are using one object instead of two functions, but without "out" property you would have same error. I did. Adding "out" fixes it in a same way as @noob already answered, just with different syntax, so it might help someone.

$('#nav-main ul li').hoverIntent({
  over: function () {
    $(this).find('.dropdown').stop(true,true).slideToggle('500');
  },
  out: function() {}
});
0

I had same problem with 'parallax' plugin. I changed jQuery librery version to *jquery-1.6.4* from *jquery-1.10.2*. And error cleared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.