gpt4 book ai didi

jquery - 可点击的下拉菜单

转载 作者:太空宇宙 更新时间:2023-11-04 03:19:09 25 4
gpt4 key购买 nike

我的网站顶部有以下可点击的导航菜单:

jsFiddle

此代码段中也提供了代码:

$("nav td a").click(function(e) {
if ($(this).parent().hasClass('selected')) {
$("nav .selected div div").slideUp(200);
$("nav .selected").removeClass("selected");
//alert("HERE!");
} else {
$("nav .selected div div").slideUp(200);
$("nav .selected").removeClass("selected");
//alert("NO HERE");
if ($(this).next(".subs").length) {
$(this).parent().addClass("selected");
$(this).next(".subs").children().slideDown(200);
}
}
e.stopPropagation();
});

$("body").click(function() {
$("nav .selected div div").slideUp(200);
$("nav .selected").removeClass("selected");
});
nav {
background: #f0f7fa;
color: #85a0ad;
margin: 40px -38px 0 -38px;
padding: 10px 38px;
}
nav table {
border-collapse: collapse;
width: 100%;
}
nav td {
padding: 0;
position: relative;
}
nav > td > a {
display: block;
color: #f0f7fa;
position: relative;
text-decoration: none;
}
nav > td.selected > a {
z-index: 2;
}
nav td div {
position: relative;
}
nav li div {
position: relative;
}
nav td div div {
background-color: #f0f0f0;
padding: 12px 0;
display: none;
font-size: 0.95em;
margin: 0;
position: absolute;
top: -1px;
z-index: 1;
width: 190px;
}
nav td div div.wrp2 {
width: 380px;
}
nav .sep {
left: 190px;
border-left: 1px solid #044a4b;
bottom: 0;
height: auto;
margin: 15px 0;
position: absolute;
top: 0;
width: 1px;
}
nav td div ul {
padding-left: 10px;
padding-right: 10px;
position: relative;
width: 170px;
float: left;
list-style-type: none;
}
nav td div ul li {
margin: 0;
padding: 0;
}
nav td ul ul {
padding: 0 0 8px;
}
nav td ul ul li {
margin: 0;
padding: 0;
}
nav td ul ul li a {
color: #044a4b;
display: block;
margin-bottom: 1px;
padding: 3px 5px;
text-decoration: none;
font-size: 1.1em;
}
nav td ul ul li a:hover {
background-color: #85a0ad;
color: #fff;
}
nav td.gap {
width: 33%;
}
nav.top {
margin-top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="top">
<table>
<tr>
<td>&#x25BE;&nbsp;<a href="#" class="clicker">Lectures</a>
<div class="subs">
<div class="wrp2">
<ul class="navul">
<li>
<h4>Intros</h4>
<ul>
<li><a class=lecture href="lecture00.html">Introduction</a>
</li>
</ul>
</li>
<li>
<h4>Graph<span class="full-nav">&nbsp;Theory</span></h4>
<ul>
<li><a class=lecture href="lecture01.html">Euler Circuits</a>
</li>
<li><a class=lecture href="lecture02.html">Beyond Euler Circuits</a>
</li>
<li><a class=lecture href="lecture03.html">Hamiltonian Circuits</a>
</li>
<li><a class=lecture href="lecture04.html">Travelling Salesmen</a>
</li>
<li><a class=lecture href="lecture05.html">Minimum Cost&mdash;Spanning Trees</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<td class="gap">&nbsp;
<td>&equiv;&nbsp;<a href="#">Course<span class="full-nav">&nbsp;Info</span></a>
</tr>
</table>
</nav>

我还想在页面底部放置相同的菜单,可点击菜单向上而不是向下打开。我看过this post ,但它是关于一个在悬停时打开的菜单,而我的是通过单击打开的。我对几件事感到困惑:

  1. 我应该将“position: absolute; bottom: 100%”放在 CSS 中的什么位置?
  2. 当菜单向上打开时,我应该如何更改 slideUp/slideDown 调用?
  3. 如何防止一个菜单干扰另一个菜单? [我的意思是,在我早期的尝试中,单击底部菜单会立即自行关闭,因为 jQuery 代码先执行 slideUp 然后 slideDown,但这也许不是问题。]

最佳答案

在这里查看 fiddle :http://jsfiddle.net/h5fjwju6/

只需稍微更新您的 CSS,即可设置 .top 类设置和 .bottom 类设置。您的任何 jQuery 都没有变化!...

HTML 更新:

<!-- Just add another nav with class bottom, below your current top nav -->

<nav class="bottom">
<table>
<tr>
...

CSS 更新:

nav {
background: #f0f7fa;
color: #85a0ad;
margin: 40px -38px 0 -38px;
padding: 10px 38px;
position:fixed; // <-- added this
}

nav td div div {
background-color: #f0f0f0;
padding: 12px 0;
display: none;
font-size: 0.95em;
margin: 0;
position: absolute;
//top: -1px; <-- removed this
z-index: 1;
width: 190px;
}
nav.top { // <-- added this
top: 1px;
}
nav.top td div div { // <-- added this
top: 1px;
}
nav.bottom { // <-- added this
bottom: 0px;
}
nav.bottom td div div { // <-- added this
bottom: 25px;
}

关于jquery - 可点击的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28187422/

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