LeMisterV / jquery.hoverintent

jQuery plugin that implements two new events : mouseenterintent and mouseleaveintent
18 stars 1 forks source link

Options Value is not respected #2

Closed Myztiq closed 12 years ago

Myztiq commented 12 years ago

I have been digging through the code trying to figure out why the following does not work.

$('.targetDiv').hoverIntent(function(){ console.log('Over'); },function(){ console.log('Out'); },{ enterTimeout:1000, leaveTimeout:2000, });

What happens is it will log out Over right away instead of waiting a second. Also the leave timeout is not waiting any time either.It looks like the options element is not being used when the area with: // Compatibility with Brian Cherne's plugin runs. If I add options to the function: function(f, g) and log the options it has my data, but that is not getting passed anywhere.

What am I doing wrong?

LeMisterV commented 12 years ago

HI !

I think you misunderstood some parts of this plugin. The goal of this plugin is not to delay the mouseenter event. The goal is to trigger mouseenterintent as soon as we think the user really wants to enter the element.

There's two way to guess the users wants to enter an element :

First I check the speed limit :

If the cursor, while hovering the element, goes slower than a defined speed (option maxSpeed), I consider that the user wants to enter the element and I trigger mouseenterintent.

Than I check time limit :

If the user keeps his cursor over the element but stays over the speed limit (no event triggered because of the mouse speed), than I check the second control : the time limit defined by enterTimeout. if the cursor stays over the element more than this time the mouseenterintent event is triggered.

If you only want to use the time limit and not the speed limit, it's possible. You just have to define a negative maxSpeed (maxSpeed : -1).

Than the only control will be the time the user stays over the element. I think it removes a very interesting part of this plugin but you can do whatever you want of course.

Myztiq commented 12 years ago

That makes perfect sense, thank you very much.