Home >Web Front-end >JS Tutorial >Sharing the solution to the problem that the hover event in jQuery keeps flashing in IE
When using the hover event of jQuery, the menu often flashes because the mouse slides too fast. I believe many friends have encountered this. I have seen that the vertical drop-down menu I made keeps shrinking, which is very annoying. I also encountered this situation when I was designing a menu for a website today. As a result, I searched on Baidu for a long time and could not find a solution. Let’s complain here. Baidu is too bad, and the included content is of little value. Finally, I found a solution on Google. Now I will teach you how to solve the problem of jQuery hover causing non-stop flashing in IE.
$("#category ul").find("li").each( function() { $(this).mouseover( function() { $(this).children("ul").show(); } ); $(this).mouseout( function() { $(this).children("ul").hide(); } ); } );
The menu will continue to flash when the mouse moves in the drop-down menu, indicating that the mouseover and mouseout events are continuously triggered.
In fact, the solution is very simple: change mouseover to mouseenter and mouseout to mouseleave. The mouseenter and mouseleave events are implemented in the jQuery library and are not native events of the browser. But the most important thing is to solve the problem of the menu constantly flashing!
$("#category ul").find("li").each( function() { $(this).mouseenter(function() { $(this).children("ul").show(); } ); $(this).mouseleave(function() { $(this).children("ul").hide(); } ); } );
The above is the detailed content of Sharing the solution to the problem that the hover event in jQuery keeps flashing in IE. For more information, please follow other related articles on the PHP Chinese website!