gpt4 book ai didi

jquery - 保持父 li 就像悬停在子菜单上一样

转载 作者:太空宇宙 更新时间:2023-11-04 05:23:12 26 4
gpt4 key购买 nike

尝试在打开子菜单时获取具有事件颜色的菜单标题

CSS:

#main-nav, #main-nav ul {
margin:0;
padding:0;
list-style:none;
list-style-position:outside;
position:relative;
line-height:1.5em;
}
#main-nav a:link, #main-nav a:active, #main-nav a:visited {
display:block;
padding:0px 5px;
color:#FFF;
text-decoration:none;
background:#03C;
}
#main-nav a:hover {
background:#CCC;
}
#main-nav li {
float:left;
position:relative;
}
#main-nav ul {
position:absolute;
width:12em;
top:auto;
display:none;
}
#main-nav li ul a {
border:1px solid #333;
border-top:0px;
width:12em;
float:left;
}
#main-nav ul ul {
top:auto;
}
#main-nav li ul ul {
left:12em;
margin:0px 0 0 10px;
}
#main-nav li:hover ul ul, #main-nav li:hover ul ul ul, #main-nav li:hover ul ul ul ul {
display:none;
}
#main-nav li:hover ul, #main-nav li li:hover ul, #main-nav li li li:hover ul, #main-nav li li li li:hover ul {
display:block;
}

J查询:

$(document).ready(function(){
$("#main-nav ul").css({display: "none"});
$("#main-nav li").hover(function(){
$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
$("ul").prev("ul").attr('style', 'background-color:#000');
},function(){
$(this).find('ul:first').css({visibility: "hidden"});
});
$("#main-nav li li a").hover(function(){
$(this).parent("a").attr('style', 'background-color:#000');
});
});

HTML/PHP

    <ul id="main-nav">
<li><a href="<?=HOME;?>">Home</a></li>
<li><a href="#">Browse</a>
<ul>
<li><a href="<?=SEARCH;?>" style="border-top:1px solid #333">Search</a></li>
<li><a href="<?=ONLINE;?>">Who's Online</a></li>
</ul>
</li>
<li><a href="#">Messages</a>
<ul>
<li><a href="<?=INBOX;?>" style="border-top:1px solid #333">Inbox</a></li>
<li><a href="<?=COMPOSE;?>">Compose</a></li>
<li><a href="<?=SENT;?>">Sent</a></li>
<li><a href="<?=TRASH;?>">Trash</a></li>
</ul>
</li>
<li><a href="#">Favorites</a>
<ul>
<li><a href="<?=MYFAVS;?>" style="border-top:1px solid #333">My Favorites</a></li>
<li><a href="<?=ONLINEFAVS;?>">Online Favorites</a></li>
<li><a href="<?=WHOSFAVS;?>">Whose Favorite Am I?</a></li>
</ul>
</li>
<li><a href="#">Account</a>
<ul>
<li><a href="<?=MYPROFILE.$uid;?>" style="border-top:1px solid #333">My Profile</a></li>
<li><a href="<?=EDITPROFILE;?>">Edit Profile / Account Settings</a> </li>
<li><a href="#" id="uploadphoto">Upload Photo's</a></li>
</ul>
</li>
<li><a href="#">Help</a>
<ul>
<li><a href="<?=CONTACT;?>" style="border-top:1px solid #333">Contact Us</a></li>
<li><a href="<?=PRIVACY;?>">Privacy Policy</a></li>
<li><a href="<?=TOS;?>">Terms of Service</a></li>
<li><a href="<?=ABOUTUS;?>">About Us</a></li>
</ul>
</li>
</ul>

最佳答案

我认为这会满足您的需求:jsfiddle

关于jquery - 保持父 li 就像悬停在子菜单上一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972785/

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