J'ai un mégamenu et je souhaite changer l'événement de clic en événement de survol. Lorsque vous passez la souris sur "Toutes les catégories" pour pouvoir afficher le sous-menu.

Pour l'instant, l'exemple ne fonctionne que pour le clic. Vous devez cliquer sur "Toutes les catégories" pour afficher toutes les catégories.

J'ai essayé de changer l'événement :

$('.categorie-title').hover(function () {
    $('.vertical-menu-list').slideToggle();
});

Mais quand vous allez avec la souris sur une catégorie ex: "IT" tout le megamenu se ferme.

Comment puis-je faire fonctionner le mégamenu du clic au survol ?

$(document).ready(function() {
	$('.categorie-title').on('click', function () {
    $('.vertical-menu-list').slideToggle();
  });		
});
li {
    list-style: none;
}
.vertical-menu {
    width: 100%;
    position: relative;
}
.vertical-menu > span {
    background: #03A9F4 none repeat scroll 0 0;
    color: #fff;
    cursor: pointer;
    display: block;
    font-size: 15px;
    font-weight: 500;
    margin: 0;
    padding: 14px 30px 12px;
    position: relative;
    text-transform: uppercase;
    height: 49px;
}

.vertical-menu > span::after, .search-box-view .submit::before {
    content: "";
    font-family: FontAwesome;
    font-size: 18px;
    font-weight: normal;
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
}

.has-mega-menu {
    line-height: 43px;
    float: left;
    padding: 0;
    background-color: #3e3e3e;
    width: 220px;
}

.vertical-menu-list {
    background: #fff none repeat scroll 0 0;
    left: 0;
    padding: 0 25px;
    position: absolute;
    top: 100%;
    width: 100%;
    z-index: 999;
    border: 2px solid #03A9F4;
    border-top-width: 0;
}

.vertical-menu-list > li {
    position: relative;
}

.vertical-menu-list > li > a, .category-menu li a {
    color: #333;
    display: block;
    font-size: 14px;
    font-weight: 400;
    line-height: 19px;
    overflow-wrap: break-word;
    padding: 17px 0;
    position: relative;
    text-align: left;
    text-transform: capitalize;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
}

.vertical-menu-list > li span, .category-sub li span {
    display: inline-block;
    width: 35px;
}

.vertical-menu-list > li:hover ul.ht-dropdown {
	visibility: visible;
    -webkiit-transform: scaleY(1);
    -webkit-transform: scaleY(1);
    transform: scaleY(1);
    opacity: 1;
}

.vertical-menu-list > li ul.megamenu {
    background: #fff none repeat scroll 0 0;
    border: 1px solid #e5e5e3;
    -webkit-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    left: 100%;
    padding: 10px;
    top: 0;
    width: 905px;
}

.vertical-menu-list .ht-dropdown:before {
    background-color: #fff;
    border-color: #f1f1f1 transparent transparent #f1f1f1;
    -o-border-image: none;
    border-image: none;
    border-style: solid;
    border-width: 1px;
    content: "";
    display: block;
    height: 15px;
    left: -8px;
    position: absolute;
    top: 21px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
    width: 15px;
}

.vertical-menu-list > li:nth-child(n) > a:after {
    content: "\f107";
    font-family: 'FontAwesome';
    position: absolute;
    top: 20px;
    right: 15px;
    -webkit-transition: all 0.5s;
    transition: all 0.5s;
}

.vertical-menu-list > li:nth-child(n):hover > a:after {
    -wekit-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
}

.has-mega-menu a:hover {
    color: #03A9F4;
    white-space: normal;
    text-decoration: none;
}

.fix {
    overflow: hidden;
}

.ht-dropdown {
    background: #fff;
    left: 0;
    opacity: 0;
    padding: 10px 20px;
    position: absolute;
    top: 100%;
    -webkiit-transform: scaleY(0);
    -webkit-transform: scaleY(0);
    transform: scaleY(0);
    -webkit-transform-origin: 0 0 0;
    transform-origin: 0 0 0;
    width: 150px;
    text-align: left;
    visibility: hidden;
    z-index: 99999999;
    -webkit-transition: 0.5s;
    transition: 0.5s;
    -webkit-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    -ms-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
}

.sub-menu.mega-menu {
    left: 100%;
    padding: 0;
    top: 0;
    background-color: #ffffff;
}

.sub-menu.mega-menu .row .mega-col {
    display: inline-block;
    position: relative;
    vertical-align: top;
    width: 20%;
    height: 100%;
    overflow: hidden;
}

.sub-menu.mega-menu .mega-content:last-child {
    border: medium none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.sub-menu.mega-menu .mega-item-title {
    font-size: 13px;
    font-family: sans-serif;
    text-align: left;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

ul.menu {
    float: left;
}

.megamenu ul {
    position: relative;
    margin: 0;
    padding: 0 15px;
}

.has-mega-menu ul.menu > li.menu-item {
    width: 100%;
    float: none;
    text-align: left;
    padding: 0 0 0 10px;
}

.main-menu ul li a, .megamenu ul li a {
    display: block;
    line-height: 1.5;
    font-size: 12px;
}

.menu-hidden {
    display: none;
}
<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div class="container">
		<div class="row">
		    <div class="col-lg-3 col-md-3 col-sm-4 hidden-xs">
		        <div class="vertical-menu">
		            <span class="categorie-title">All Categories </span>
		            <nav class="has-mega-menu">
		                <ul class="vertical-menu-list menu-hidden">
		                    <li>
								<a class="" href="javascript:void(0)"><span><i class="fa fa-leaf"></i></span>IT</a>
								<ul class="ht-dropdown megamenu">
									<li class="megamenu-three-column fix">
									<div class="sub-menu mega-menu">
										<div class="row">
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Components</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Motherboards</a></li>
													<li class="menu-item"><a href="#">Memories</a></li>
												</ul>
											</ul>
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Software</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Windows</a></li>
													<li class="menu-item"><a href="#">Office</a></li>
												</ul>
											</ul>
										</div>
									</div>
								</ul>	
							</li>
							<li>
								<a class="" href="javascript:void(0)"><span><i class="fa fa-black-tie"></i></span>Fashion</a>
								<ul class="ht-dropdown megamenu">
									<li class="megamenu-three-column fix">
									<div class="sub-menu mega-menu">
										<div class="row">
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Shoes</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Some Shoes</a></li>
													<li class="menu-item"><a href="#">Another Shoes</a></li>
												</ul>
											</ul>
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Dresses</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Dresses 1</a></li>
													<li class="menu-item"><a href="#">Dresses 2</a></li>
													<li class="menu-item"><a href="#">Dresses 3</a></li>
												</ul>
											</ul>
										</div>
									</div>
								</ul>	
							</li>
						</ul>
		            </nav>
		        </div>
		    </div>               
		</div>
	</div>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>	
</body>
</html>
0
calin24 19 mars 2019 à 13:33

2 réponses

Meilleure réponse

Vous pouvez ajouter mouseenter et mouseleave comme ci-dessous pour agir comme un survol

$(document).ready(function() {
	$('.categorie-title').on('mouseenter', function () {
    $('.vertical-menu-list').slideDown();
  });
  $('.vertical-menu').on('mouseleave', function () {
    $('.vertical-menu-list').slideUp();
  });
});
li {
    list-style: none;
}
.vertical-menu {
    width: 100%;
    position: relative;
}
.vertical-menu > span {
    background: #03A9F4 none repeat scroll 0 0;
    color: #fff;
    cursor: pointer;
    display: block;
    font-size: 15px;
    font-weight: 500;
    margin: 0;
    padding: 14px 30px 12px;
    position: relative;
    text-transform: uppercase;
    height: 49px;
}

.vertical-menu > span::after, .search-box-view .submit::before {
    content: "";
    font-family: FontAwesome;
    font-size: 18px;
    font-weight: normal;
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
}

.has-mega-menu {
    line-height: 43px;
    float: left;
    padding: 0;
    background-color: #3e3e3e;
    width: 220px;
}

.vertical-menu-list {
    background: #fff none repeat scroll 0 0;
    left: 0;
    padding: 0 25px;
    position: absolute;
    top: 100%;
    width: 100%;
    z-index: 999;
    border: 2px solid #03A9F4;
    border-top-width: 0;
}

.vertical-menu-list > li {
    position: relative;
}

.vertical-menu-list > li > a, .category-menu li a {
    color: #333;
    display: block;
    font-size: 14px;
    font-weight: 400;
    line-height: 19px;
    overflow-wrap: break-word;
    padding: 17px 0;
    position: relative;
    text-align: left;
    text-transform: capitalize;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
}

.vertical-menu-list > li span, .category-sub li span {
    display: inline-block;
    width: 35px;
}

.vertical-menu-list > li:hover ul.ht-dropdown {
	visibility: visible;
    -webkiit-transform: scaleY(1);
    -webkit-transform: scaleY(1);
    transform: scaleY(1);
    opacity: 1;
}

.vertical-menu-list > li ul.megamenu {
    background: #fff none repeat scroll 0 0;
    border: 1px solid #e5e5e3;
    -webkit-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    left: 100%;
    padding: 10px;
    top: 0;
    width: 905px;
}

.vertical-menu-list .ht-dropdown:before {
    background-color: #fff;
    border-color: #f1f1f1 transparent transparent #f1f1f1;
    -o-border-image: none;
    border-image: none;
    border-style: solid;
    border-width: 1px;
    content: "";
    display: block;
    height: 15px;
    left: -8px;
    position: absolute;
    top: 21px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
    width: 15px;
}

.vertical-menu-list > li:nth-child(n) > a:after {
    content: "\f107";
    font-family: 'FontAwesome';
    position: absolute;
    top: 20px;
    right: 15px;
    -webkit-transition: all 0.5s;
    transition: all 0.5s;
}

.vertical-menu-list > li:nth-child(n):hover > a:after {
    -wekit-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
}

.has-mega-menu a:hover {
    color: #03A9F4;
    white-space: normal;
    text-decoration: none;
}

.fix {
    overflow: hidden;
}

.ht-dropdown {
    background: #fff;
    left: 0;
    opacity: 0;
    padding: 10px 20px;
    position: absolute;
    top: 100%;
    -webkiit-transform: scaleY(0);
    -webkit-transform: scaleY(0);
    transform: scaleY(0);
    -webkit-transform-origin: 0 0 0;
    transform-origin: 0 0 0;
    width: 150px;
    text-align: left;
    visibility: hidden;
    z-index: 99999999;
    -webkit-transition: 0.5s;
    transition: 0.5s;
    -webkit-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    -ms-box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.2);
}

.sub-menu.mega-menu {
    left: 100%;
    padding: 0;
    top: 0;
    background-color: #ffffff;
}

.sub-menu.mega-menu .row .mega-col {
    display: inline-block;
    position: relative;
    vertical-align: top;
    width: 20%;
    height: 100%;
    overflow: hidden;
}

.sub-menu.mega-menu .mega-content:last-child {
    border: medium none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.sub-menu.mega-menu .mega-item-title {
    font-size: 13px;
    font-family: sans-serif;
    text-align: left;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

ul.menu {
    float: left;
}

.megamenu ul {
    position: relative;
    margin: 0;
    padding: 0 15px;
}

.has-mega-menu ul.menu > li.menu-item {
    width: 100%;
    float: none;
    text-align: left;
    padding: 0 0 0 10px;
}

.main-menu ul li a, .megamenu ul li a {
    display: block;
    line-height: 1.5;
    font-size: 12px;
}

.menu-hidden {
    display: none;
}
<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div class="container">
		<div class="row">
		    <div class="col-lg-3 col-md-3 col-sm-4 hidden-xs">
		        <div class="vertical-menu">
		            <span class="categorie-title">All Categories </span>
		            <nav class="has-mega-menu">
		                <ul class="vertical-menu-list menu-hidden">
		                    <li>
								<a class="" href="javascript:void(0)"><span><i class="fa fa-leaf"></i></span>IT</a>
								<ul class="ht-dropdown megamenu">
									<li class="megamenu-three-column fix">
									<div class="sub-menu mega-menu">
										<div class="row">
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Components</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Motherboards</a></li>
													<li class="menu-item"><a href="#">Memories</a></li>
												</ul>
											</ul>
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Software</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Windows</a></li>
													<li class="menu-item"><a href="#">Office</a></li>
												</ul>
											</ul>
										</div>
									</div>
								</ul>	
							</li>
							<li>
								<a class="" href="javascript:void(0)"><span><i class="fa fa-black-tie"></i></span>Fashion</a>
								<ul class="ht-dropdown megamenu">
									<li class="megamenu-three-column fix">
									<div class="sub-menu mega-menu">
										<div class="row">
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Shoes</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Some Shoes</a></li>
													<li class="menu-item"><a href="#">Another Shoes</a></li>
												</ul>
											</ul>
											<ul class="mega-col"><li class="mega-content">
												<a href="#" class="mega-item-title">Dresses</a>
												<ul class="menu">
													<li class="menu-item"><a href="#">Dresses 1</a></li>
													<li class="menu-item"><a href="#">Dresses 2</a></li>
													<li class="menu-item"><a href="#">Dresses 3</a></li>
												</ul>
											</ul>
										</div>
									</div>
								</ul>	
							</li>
						</ul>
		            </nav>
		        </div>
		    </div>               
		</div>
	</div>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>	
</body>
</html>
1
Hiren Vaghasiya 19 mars 2019 à 11:00

Eh bien, il fallait que vous modifiiez le source javascript du menu.

Il devrait donc ressembler à ceci.

<div class="container">
    <div class="main">
        <nav id="cbp-hrmenu" class="cbp-hrmenu">
            <ul>
                <li>    <a href="#">Products</a>

                    <div class="cbp-hrsub">
                        <div class="cbp-hrsub-inner">
                            <div>
                                    <h4>Learning &amp; Games</h4>

                                <ul>
                                    <li><a href="#">Catch the Bullet</a>
                                    </li>
                                    <li><a href="#">Snoopydoo</a>
                                    </li>
                                    <li><a href="#">Fallen Angel</a>
                                    </li>
                                    <li><a href="#">Sui Maker</a>
                                    </li>
                                    <li><a href="#">Wave Master</a>
                                    </li>
                                    <li><a href="#">Golf Pro</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Utilities</h4>

                                <ul>
                                    <li><a href="#">Gadget Finder</a>
                                    </li>
                                    <li><a href="#">Green Tree Express</a>
                                    </li>
                                    <li><a href="#">Green Tree Pro</a>
                                    </li>
                                    <li><a href="#">Wobbler 3.0</a>
                                    </li>
                                    <li><a href="#">Coolkid</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Education</h4>

                                <ul>
                                    <li><a href="#">Learn Thai</a>
                                    </li>
                                    <li><a href="#">Math Genius</a>
                                    </li>
                                    <li><a href="#">Chemokid</a>
                                    </li>
                                </ul>
                                    <h4>Professionals</h4>

                                <ul>
                                    <li><a href="#">Success 1.0</a>
                                    </li>
                                    <li><a href="#">Moneymaker</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /cbp-hrsub-inner -->
                    </div>
                    <!-- /cbp-hrsub -->
                </li>
                <li>    <a href="#">Downloads</a>

                    <div class="cbp-hrsub">
                        <div class="cbp-hrsub-inner">
                            <div>
                                    <h4>Education &amp; Learning</h4>

                                <ul>
                                    <li><a href="#">Learn Thai</a>
                                    </li>
                                    <li><a href="#">Math Genius</a>
                                    </li>
                                    <li><a href="#">Chemokid</a>
                                    </li>
                                </ul>
                                    <h4>Professionals</h4>

                                <ul>
                                    <li><a href="#">Success 1.0</a>
                                    </li>
                                    <li><a href="#">Moneymaker</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Entertainment</h4>

                                <ul>
                                    <li><a href="#">Gadget Finder</a>
                                    </li>
                                    <li><a href="#">Green Tree Express</a>
                                    </li>
                                    <li><a href="#">Green Tree Pro</a>
                                    </li>
                                    <li><a href="#">Holy Cannoli</a>
                                    </li>
                                    <li><a href="#">Wobbler 3.0</a>
                                    </li>
                                    <li><a href="#">Coolkid</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Games</h4>

                                <ul>
                                    <li><a href="#">Catch the Bullet</a>
                                    </li>
                                    <li><a href="#">Snoopydoo</a>
                                    </li>
                                    <li><a href="#">Fallen Angel</a>
                                    </li>
                                    <li><a href="#">Sui Maker</a>
                                    </li>
                                    <li><a href="#">Wave Master</a>
                                    </li>
                                    <li><a href="#">Golf Pro</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /cbp-hrsub-inner -->
                    </div>
                    <!-- /cbp-hrsub -->
                </li>
                <li>    <a href="#">Applications</a>

                    <div class="cbp-hrsub">
                        <div class="cbp-hrsub-inner">
                            <div>
                                    <h4>Learning &amp; Games</h4>

                                <ul>
                                    <li><a href="#">Catch the Bullet</a>
                                    </li>
                                    <li><a href="#">Snoopydoo</a>
                                    </li>
                                </ul>
                                    <h4>Utilities</h4>

                                <ul>
                                    <li><a href="#">Gadget Finder</a>
                                    </li>
                                    <li><a href="#">Green Tree Express</a>
                                    </li>
                                    <li><a href="#">Green Tree Pro</a>
                                    </li>
                                    <li><a href="#">Wobbler 3.0</a>
                                    </li>
                                    <li><a href="#">Coolkid</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Education</h4>

                                <ul>
                                    <li><a href="#">Learn Thai</a>
                                    </li>
                                    <li><a href="#">Math Genius</a>
                                    </li>
                                    <li><a href="#">Chemokid</a>
                                    </li>
                                </ul>
                                    <h4>Professionals</h4>

                                <ul>
                                    <li><a href="#">Success 1.0</a>
                                    </li>
                                    <li><a href="#">Moneymaker</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /cbp-hrsub-inner -->
                    </div>
                    <!-- /cbp-hrsub -->
                </li>
                <li>    <a href="#">Projects</a>

                    <div class="cbp-hrsub">
                        <div class="cbp-hrsub-inner">
                            <div>
                                    <h4>Learning &amp; Games</h4>

                                <ul>
                                    <li><a href="#">Catch the Bullet</a>
                                    </li>
                                    <li><a href="#">Snoopydoo</a>
                                    </li>
                                    <li><a href="#">Fallen Angel</a>
                                    </li>
                                    <li><a href="#">Sui Maker</a>
                                    </li>
                                    <li><a href="#">Wave Master</a>
                                    </li>
                                    <li><a href="#">Golf Pro</a>
                                    </li>
                                </ul>
                                    <h4>Utilities</h4>

                                <ul>
                                    <li><a href="#">Gadget Finder</a>
                                    </li>
                                    <li><a href="#">Green Tree Express</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Entertainment</h4>

                                <ul>
                                    <li><a href="#">Gadget Finder</a>
                                    </li>
                                    <li><a href="#">Green Tree Express</a>
                                    </li>
                                    <li><a href="#">Green Tree Pro</a>
                                    </li>
                                    <li><a href="#">Holy Cannoli</a>
                                    </li>
                                    <li><a href="#">Wobbler 3.0</a>
                                    </li>
                                    <li><a href="#">Coolkid</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /cbp-hrsub-inner -->
                    </div>
                    <!-- /cbp-hrsub -->
                </li>
                <li>    <a href="#">Freeware</a>

                    <div class="cbp-hrsub">
                        <div class="cbp-hrsub-inner">
                            <div>
                                    <h4>Utilities</h4>

                                <ul>
                                    <li><a href="#">Green Tree Pro</a>
                                    </li>
                                    <li><a href="#">Wobbler 3.0</a>
                                    </li>
                                    <li><a href="#">Coolkid</a>
                                    </li>
                                </ul>
                                    <h4>Education</h4>

                                <ul>
                                    <li><a href="#">Learn Thai</a>
                                    </li>
                                    <li><a href="#">Math Genius</a>
                                    </li>
                                    <li><a href="#">Chemokid</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Professionals</h4>

                                <ul>
                                    <li><a href="#">Success 1.0</a>
                                    </li>
                                    <li><a href="#">Moneymaker</a>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                    <h4>Learning &amp; Games</h4>

                                <ul>
                                    <li><a href="#">Catch the Bullet</a>
                                    </li>
                                    <li><a href="#">Snoopydoo</a>
                                    </li>
                                    <li><a href="#">Fallen Angel</a>
                                    </li>
                                    <li><a href="#">Sui Maker</a>
                                    </li>
                                    <li><a href="#">Wave Master</a>
                                    </li>
                                    <li><a href="#">Golf Pro</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /cbp-hrsub-inner -->
                    </div>
                    <!-- /cbp-hrsub -->
                </li>
            </ul>
        </nav>
    </div>
</div>

Et le code après embellissement et modifications

var cbpHorizontalMenu = (function () {
    var b = $("#cbp-hrmenu > ul > li"),
        g = b.children("a"),
        c = $("body"),
        d = -1;

    function f() {
        g.on("mouseover", a);
        b.on("mouseover", function (h) {
            h.stopPropagation()
        })
    }

    function a(j) {
        if (d !== -1) {
            b.eq(d).removeClass("cbp-hropen")
        }
        var i = $(j.currentTarget).parent("li"),
            h = i.index();
        if (d === h) {
            i.removeClass("cbp-hropen");
            d = -1
        } else {
            i.addClass("cbp-hropen");
            d = h;
            c.off("click").on("click", e)
        }
        return false
    }

    function e(h) {
        b.eq(d).removeClass("cbp-hropen");
        d = -1
    }
    return {
        init: f
    }
})();

$(function () {
    cbpHorizontalMenu.init();
});

Sur jsfiddle

0
Tanbir Chowdhury 19 mars 2019 à 10:40