Solve the problem of jquery mouseout mouseover multiple executions

Source: Internet
Author: User

With Jquery,mouseout,mouseover, with the mouse movement, the event was triggered many times, the same as JS Onmouseover,onmouseout. The ultimate solution is to replace mouseover with Jquery,mouseleave instead of Mouseout;mouseenter.
Mouseleave,mouseenter the mouse to leave, triggering the event when entering the outermost label.
Mouseout,mouseover the mouse to leave and enter the inside label when the event triggers.

1, single internal element, no difference


<div id= "Test2" >

</div>

$ ("#test2"). MouseLeave (function () {
Console.log (' out ');
}). MouseEnter (function () {
Console.log (' in ');
});

$ ("#test2"). Mouseout (function () {
Console.log (' out ');
}). mouseover (function () {
Console.log (' in ');
});

The above two code JS code executes separately, the result of execution is the same. Like Mouseover,onmouseover,mouseenter, Mouseout,onmouseout,mouseleave.

2, multiple internal elements, Mouseleave,mouseenter will only execute once


<div id= "Test2" >
<ul>
<li>test</li>
<li>test1</li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
</div>

If you change the HTML code to UL this situation, when the mouse enters, leaves the Div, the Mouseleave,mouseenter will only perform once, while the other, with the mouse in the UL between each Li to slide, will be executed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.