Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid massive onmouseover onmouseout firing?

I have a table with some columns. In each of them is a picture where I have an onmouseover/onmouseout event on it, which shows a message in a div and hides the message.

My problem is, after a user moves quickly from left to right over a lot of images, all mouseover and mouseout events of the images are executed, which looks stupid...

Is it possible to rearrange the internal event stack to avoid this, such that the user executes only the current event (mostly the first one) and then the last one, if it is not the same type?

For example, if mouseover over first image is executed and the mouse moving position stops over an image three times next to the first one. I can avoid all other events firing, because the mouse stopped over an image and the mouseover is like the one where I stopped with the mouse.

How can I avoid this multiple event firing?

like image 925
stephan Avatar asked Feb 01 '26 12:02

stephan


2 Answers

You need to check out the hoverIntent plugin, which addresses this problem.

like image 144
karim79 Avatar answered Feb 04 '26 03:02

karim79


We've had the exact same problem, What we've done is on the mouseover event is to set a variable _mouseOn to true (set to false on mouseout) then set a oneTime event over that fires in say 500 ms.. The one time event will check if the _mouseOn is true and display the image

    function Hover() {
  _mouseOn = true;
  $(document).oneTime(500, "500ms", functionToCheckTheMouseOnAndDisplayTheImage);
};
like image 44
TWith2Sugars Avatar answered Feb 04 '26 02:02

TWith2Sugars