Cleartimeout Eliminate flashing

Source: Internet
Author: User

Requirements: When the mouse is placed above the parent menu, the submenu below is displayed. When the mouse moves away from the submenu or parent menu, the submenu is closed. The final effect is as follows:

PS: This is a common requirement, and the most common practice is to nest a UL element underneath the LI element to contain child elements. This approach can be completely controlled with CSS. But today this submenu is separate from the navigation bar. The Header-tags block is displayed when the mouse is over the product.

  <ulclass= "header-nav">                            <Liclass= "Nav-item Home"><ahref= "@Url. Action ("Index "," Home ")">Home</a></Li>                            <Liclass= "Nav-item Products"ID= "Header_tags">                                <ahref="#">Products<spanclass= "Icon-caret-down"></span></a>  ....                            </Li></ul><Divclass= "header-tags">                            <ul>                                <Li>                                    <imgclass= "Screening-img-normal"src= "~/content/static/all.png">                                    <imgclass= "Screening-img-hover"src= "~/content/static/all1.png">                                    <P>All</P>                                </Li>                                <LiTagID= "4">                                    <imgclass= "Screening-img-normal"src= "~/content/static/shafa.png">                                    <imgclass= "Screening-img-hover"src= "~/content/static/shafa1.png">                                    <P>Sofa</P>                                </Li>                                <LiTagID= "3">                                    <imgclass= "Screening-img-normal"src= "~/content/static/zuoyi.png">                                    <imgclass= "Screening-img-hover"src= "~/content/static/zuoyi1.png">                                    <P>Seat</P>                                </Li>....</Div>

This cannot be fully controlled with CSS (hover can only control child elements or sibling elements).

/* Father */ #a: Hover #b {Display: block/* brother */#a: hover + #b{display:  Block}

The above situation is going to use a script. This involves moving the #header_tags and. Header-tags two elements into the move. When the mouse moves into the #header_tags,.header-tags display, when the mouse is moved into the. Header-tags, the #header_tags Moveout event cannot be triggered immediately, while the tags continue to display. Only the mouse from #header_tags and. Header-tags left without re-entry before the menu will be closed.

$(function () {        varTagstime; $ (document). On (' MouseOver mouseout ', ' #header_tags ',function(event) {var$headerTagsBox = $ ('. Header-tags ')); if(Event.type = = ' MouseOver ') { cleartimeout(tagstime); $headerTagsBox. Slidedown (300); }            Else if(Event.type = = ' Mouseout ') {Tagstime= SetTimeout (function() {$headerTagsBox. Slideup (200); }, 200);        }        }); $('. Header-tags '). Hover (function() {cleartimeout (tagstime); },function(){            var$me = $ ( This); tagstime = SetTimeout (function() {$me. Slideup (200); }, 200);    }); });

If the timer is not cleared here and the delay is executed, the navigation bar will flash continuously. cannot be clicked at all.

Cleartimeout Eliminate flashing

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.