需要在子菜单上停留子菜单的弹出菜单引导程序

时间:2018-09-10 15:15:46

标签: drop-down-menu

我正在使用弹出菜单,将鼠标悬停在弹出菜单上之前,该菜单应保持可见状态,直到单击下拉菜单外部的某个位置为止。我在下面有标记,还有一些jQuery函数可以用来测试该理论,但无法正常工作。整个需求是,当您将鼠标悬停在父菜单上并且出现主下拉菜单时,它将一直保持该状态,直到您在下拉区域之外单击或转到另一个类别为止。封装的子菜单也应如此。感谢您的协助。

<ul class="mainDropDown">
                                            <li class="dropdown-submenu" role="menu">
                                                <a tabindex="1" href="searchResults.html" id="shoppingMenuLabel">
                                                    <div class="fa fa-tags"> </div>Shopping
                                                </a>
                                                <ul class="dropdown-menu">
                                                    <li class="dropdown-submenu" role="menu">
                                                        <a tabindex="1" href="searchResults.html" id="appleStoreMenuLabel">
                                                            Apple Store</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">iPods </a></li>
                                                            <li><a href="searchResults.html">iPod Accessories </a></li>
                                                            <li><a href="searchResults.html">Watches</a></li>
                                                            <li><a href="searchResults.html">Mac Systems</a></li>
                                                            <li><a href="searchResults.html">iPads</a></li>
                                                            <li><a href="searchResults.html">Shop All Apple Store</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu">
                                                        <a tabindex="1" href="searchResults.html" id="babyMenuLabel">
                                                            Baby</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Clothing</a></li>
                                                            <li><a href="searchResults.html">Feeding</a></li>
                                                            <li><a href="searchResults.html">Gear </a></li>
                                                            <li><a href="searchResults.html">Maternity</a></li>
                                                            <li><a href="searchResults.html">Nursery </a></li>
                                                            <li><a href="searchResults.html">Care & Safety</a></li>
                                                            <li><a href="searchResults.html">Shop All Baby</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu">
                                                        <a tabindex="1" href="searchResults.html" id="booksMenuLabel">
                                                            Books</a>
                                                        <ul class="dropdown-menu dropup">
                                                            <li><a href="searchResults.html">Autobiography & Biography</a></li>
                                                            <li><a href="searchResults.html">Cooking </a></li>
                                                            <li><a href="searchResults.html">Health & Fitness</a></li>
                                                            <li><a href="searchResults.html">History</a></li>
                                                            <li><a href="searchResults.html">Humor </a></li>
                                                            <li><a href="searchResults.html">Juvenile NonFiction</a></li>
                                                            <li><a href="searchResults.html">Juvenile Fiction</a></li>
                                                            <li><a href="searchResults.html">Religion</a></li>
                                                            <li><a href="searchResults.html">Social Science</a></li>
                                                            <li><a href="searchResults.html">Sports & Recreation</a></li>
                                                            <li><a href="searchResults.html">Shop All Books</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu">
                                                        <a tabindex="1" href="searchResults.html" id="electronicsMenuLabel">
                                                            Electronics</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="fashionAccMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Fashion Accessories</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="giftBasketsMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Gift Baskets</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="homeGardenMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Home & Garden</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="jewelryMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Jewelry</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="moviesMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Movies</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="musicMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            Music</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu">
                                                        <a tabindex="1" href="searchResults.html" id="officeProductsMenuLabel">
                                                            Office Products</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                    <li class="dropdown-submenu" role="menu" id="onSaleNowMenuLabel">
                                                        <a tabindex="1" href="searchResults.html">
                                                            On Sale Now!</a>
                                                        <ul class="dropdown-menu">
                                                            <li><a href="searchResults.html">Link 1</a></li>
                                                            <li><a href="searchResults.html">Link 2 </a></li>
                                                            <li><a href="searchResults.html">Link 3</a></li>
                                                        </ul>
                                                    </li>
                                                </ul>
                                            </li>
                                        </ul>

jQuery

var timer;

        $(".dropdown-submenu").on("mouseover", function () {
            clearTimeout(timer);
            openSubmenu();
        }).on("mouseleave", function () {
            timer = setTimeout(
                closeSubmenu, 3000);
        });

        function openSubmenu() {
            $(".dropdown-menu").addClass("open");
        }

        function closeSubmenu() {
            $(".dropdown-menu").removeClass("open");
        }

CSS:

<style>
        .dropdown-submenu {
            position: initial;
        }

        ul.dropdown-menu li a{
            transition-timing-function: ease-in-out;
            -moz-transition-timing-function: ease-in-out;
            -o-transition-timing-function: ease-in-out;
            -webkit-transition-timing-function: ease-in-out;
            transition-duration: 5s;
        }

        ul.dropdown-menu li.dropdown-submenu{
            transition-timing-function: ease-in-out;
            -moz-transition-timing-function: ease-in-out;
            -o-transition-timing-function: ease-in-out;
            -webkit-transition-timing-function: ease-in-out;
            transition-duration: 5s;
        }
    li.dropdown-submenu a ul.dropdown-menu{
        transition: ease-out;
    }

        .dropdown-content a:hover{
            background: transparent;
        }

        .dropdown-submenu>.dropdown-menu {
            top: 0;
            left: 95%;
            margin-top: -6px;
            margin-left: -1px;
            border: 0;
        }

        .dropdown-submenu:hover>.dropdown-menu {
            display: block;
        }

        .dropdown-submenu>a:after {
            display: block;
            content: " ";
            float: right;
            width: 0;
            height: 0;
            border-color: transparent;
            border-style: solid;
            border-width: 5px 0 5px 5px;
            border-left-color: searchResults.htmlccc;
            margin-top: 5px;
            margin-right: -10px;
        }

        .dropdown-submenu:hover>a:after {
            border-left-color: searchResults.htmlfff;
        }

        .dropdown-submenu.pull-left {
            float: none;
        }

        .dropdown-submenu.pull-left>.dropdown-menu {
            left: -100%;
            margin-left: 10px;
            border: 0;
        }

        ul.mainDropDown {
            margin: 0;
            padding: 0;
        }

        ul.mainDropDown li {
            list-style: none;
        }

        ul.dropdown-menu {
            width: 285px;
        }

        li.dropdown-submenu a {
            display: block;
        }

        @media only screen and (max-width: 800px) {
            ul.dropdown-menu {
                width: 150px;
            }
        }

        .dropup {
            list-style: none;
            /*position: relative;
            display: inline-block;*/
        }

        .dropup-content {
            display: none;
            position: absolute;
            background-color: #f1f1f1;
            min-width: 160px;
            bottom: 50px;
            z-index: 1;
        }

        .dropup-content a {
            color: black;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
        }

        .dropup-content a:hover {
            background-color: #ccc
        }

        .dropup:hover .dropup-content {
            display: block;
        }

        .dropup:hover .dropbtn {
            background-color: #3e8e41;
        }
    </style>

0 个答案:

没有答案