gpt4 book ai didi

javascript - 展开一个子菜单其他人应该自动隐藏在 jquery 中

转载 作者:行者123 更新时间:2023-11-28 07:33:53 25 4
gpt4 key购买 nike

我正在尝试使用 CSS 和 JQuery 制作可扩展的 Accordion 菜单,我想制作一个垂直的 Accordion 菜单并在我单击其他主要链接时隐藏子菜单,有人可以帮我做这个吗。

JSFiddle Link

$(function() {

$('.submenu-class li').has('.mainmenu-submenu, .mainmenu-submenu-sub, .mainmenu-submenu-sub-sub').prepend('<em class="mainmenu-click"><i class="arrowupdown"></i></em>');

$('.submenu-class li').has('.megamenu').prepend('<em class="mainmenu-click"><i class="arrowupdown"></i></em>');

$('.mainmenu-mobile').click(function(){
$('.submenu-class').slideToggle('slow');
});
$('.mainmenu-click').click(function(){
$(this).siblings('.mainmenu-submenu').slideToggle('slow');
$(this).children('.mainmenu-arrow').toggleClass('mainmenu-rotate');
$(this).siblings('.mainmenu-submenu-sub').slideToggle('slow');
$(this).siblings('.mainmenu-submenu-sub-sub').slideToggle('slow');
$(this).siblings('.megamenu').slideToggle('slow');

});

});
 
.clearfix:before, .clearfix:after{content: ""; display: table;}.clearfix:after{clear: both;}.clearfix{zoom: 1;}.cl{clear: both;}
ul, ol{margin-top:0px; margin-right:0px; margin-left:0px; margin-bottom:0px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding:0px ; list-style:none;}

.submenu-class li a{
display:block;
background-color:#fff;
color:#424242;
padding:0px 14px; line-height:48px;
border-right:1px solid rgba(0,0,0,0.10);
text-decoration:none;}


.mainmenu-click {
position:absolute;
top:0;
right:0;
display:block;
cursor:pointer;
width:100%;
}

.mainmenu-click i{
float:right;
display:block;
height:23px;
width:25px;
margin-top:11px;
margin-right:8px;
background-size:25px;
font-size:21px;
color:rgba(0,0,0,0.25);

}


.mainmenu-submenu-sub{
width:100% ;
position:static ;
left:100% ;
top:0 ;
display:none;
margin:0px ;
padding:0px ;
border:solid 0px ;
transform:none ;
opacity:1 ;
visibility:visible ;
}

.mainmenu-submenu-sub li{
margin:0px 0px 0px 0px ;
padding:0px;
position:relative;}

.mainmenu-submenu-sub a{
display:block;
padding:10px 25px 10px 25px;
border-bottom:solid 1px #ccc;
font-weight:normal;}



.mainmenu-submenu-sub-sub{
width:100% ;
position:static ;
left:100% ;
top:0 ;
display:none;
margin:0px ;
padding:0px ;
border:solid 0px ;
transform:none ;
opacity:1 ;
visibility:visible ;
}

.mainmenu-submenu-sub-sub li{
margin:0px 0px 0px 0px ;}

.mainmenu-submenu-sub-sub a{
display:block;
color:#000;
padding:10px 25px;
background:#000 ;
border-bottom:solid 1px #ccc;
font-weight:normal;}


.mainmenu{position: relative;}

.arrowupdown{ width:9px; height:9px; background-color:#ccc; }

.mainmenu .submenu-class li{
width:240px;
display:block;
float:none;
border-right:none;
background-color:transparent;
position:relative;
white-space:inherit;}

.mainmenu .submenu-class li a{
padding:9px 32px 9px 17px;
font-size:14px;
text-align:left;
border-right:solid 0px;
background-color:transparent;
color:#666666;
line-height:25px;
border-bottom:1px solid;
border-bottom-color:rgba(0,0,0,0.13);}


.submenu-class .mainmenu-submenu{
transform:none ;
opacity:1 ;
display:none;
position:relative ;
top:0px;
background-color:#fff ;
border:solid 1px #ccc;
padding:0px;
visibility:visible ;
}

.submenu-class .mainmenu-submenu li a{
line-height:20px;
height:36x;
background-color:#fff ;
font-size:13px ;
padding:8px 0px 8px 18px;
color:#8E8E8E;}

.submenu-class .megamenu{
background-color:#e7e7e7;
color:#666666;
display:none;
position:relative ;
top:0px;
padding:0px;
border:solid 0px;
transform:none ;
opacity:1 ;
visibility:visible ;
}

.submenu-class li:hover .megamenu{display:none; position:relative ; top:0px; }
.megamenu .title{ color:#666666; font-size:15px ; padding:10px 8px 10px 0px;}
.halfdiv .title{ padding-left:15px;}
.megamenu > ul{
width:100% ;
margin:0px;
padding:0px;
font-size:13px ;}

.megamenu ul li a{
padding:9px 14px ;
line-height:normal ;
font-size:13px ;
background-color:#e7e7e7 ;
color:#666666;}

.mainmenu {
width:100%;
height: 100%;
position: fixed;
left: 0;
top: 0;
margin: 0;
background-color: #fff;
border-radius:0px;
z-index:100;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
border:none ;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="mainmenu clearfix">
<ul class="submenu-class">
<li><a href="#"><span class="hometext">Open Menu 01</span></a></li>
<li><a href="#">Dropdowns </a>
<ul class="mainmenu-submenu">
<li><a href="#">Dummy Sub menu style 01</a></li>
<li><a href="#">Dummy Sub menu style 01</a></li>
<li><a href="#">Dummy Sub menu style 01</a></li>
<li><a href="#">Dummy Sub menu style 01</a></li>
<li><a href="#">Dummy Sub menu style 01</a>
<ul class="mainmenu-submenu-sub">
<li><a href="#">Dummy Sub menu style 02</a></li>
<li><a href="#">Dummy Sub menu style 02</a></li>
<li><a href="#">Dummy Sub menu style 02</a></li>
<li><a href="#">Dummy Sub menu style 02</a>
<ul class="mainmenu-submenu-sub-sub">
<li class=""><a href="#">Dummy Sub menu style 03</a></li>
<li class=""><a href="#">Dummy Sub menu style 03</a></li>
<li class=""><a href="#">Dummy Sub menu style 03</a></li>
<li class=""><a href="#">Dummy Sub menu style 03</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Open Page text Menu 01 </a>
<div class="megamenu clearfix">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</li>
<li><a href="#">Open Page text Menu 01 </a>
<div class="megamenu clearfix" > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div>
</li>
</ul>
</div>

最佳答案

这是更新的 fiddle

修改你的点击函数如下:

$('.mainmenu-click').click(function () {
$('.mainmenu-submenu').hide();
$(this).siblings('.mainmenu-submenu').show();
$(this).children('.mainmenu-submenu').slideToggle('slow');
$(this).children('.mainmenu-arrow').toggleClass('mainmenu-rotate');
$(this).siblings('.mainmenu-submenu-sub').slideToggle('slow');
$(this).siblings('.mainmenu-submenu-sub-sub').slideToggle('slow');
$('.megamenu').hide();
$(this).siblings('.megamenu').slideToggle('slow');
});

首先需要关闭所有已经展开的 Accordion ,然后显示事件的 Accordion 。希望这会有所帮助。

关于javascript - 展开一个子菜单其他人应该自动隐藏在 jquery 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com