我正在网站上练习javascript而且我无法解决这个问题。 由于某种原因,第二个下拉菜单不会下降。我添加了console.log(" hover")并显示消息,这意味着它检测到悬停但没有显示菜单。 我想只显示我悬停的菜单。 https://jsfiddle.net/py8mkvxq/
Get-Item 'foo.txt' | Rename-Item -NewName { $_.name -replace $_.basename, ((Get-Date -format 'yyyyMMdd.hhmm') + '-' + $1)}
答案 0 :(得分:2)
查看此JSfiddle!这为所有子菜单链接添加了功能。
$(".shopDrop a").hover(function(){
//find the next sibling of the `.shopDrop a` that was hovered on and fade it in
$(this).next(".shopHoverInfo").fadeIn();
}, function(){
//find the next sibling of the `.shopDrop a` that was no longer hovered on and fade it out
$(this).next(".shopHoverInfo").fadeOut();
});
你正在使用.find()
,这使得jQuery寻找#doublePoints
的孩子。然而,它不是一个孩子,而是下一个兄弟姐妹。因此,请使用.next()
。
此外,.css("display", "block")
不是必需的.fadeIn();
。
答案 1 :(得分:0)
.shopHoverInfo
不是#doublePoints
的孩子。您可以使用$.next()
代替$.find()
但是当您将鼠标悬停在子菜单上时菜单会关闭,因为您不再将鼠标悬停在#doublePoints
上。
我只需将.shopHoverInfo
元素移到#doublePoints
链接中。
https://jsfiddle.net/py8mkvxq/3/
// Drop down menu
$(".shopDrop").hide();
$(".shop ul li").hover(function() {
$(this).find(".shopDrop").slideDown();
}, function() {
$(this).find(".shopDrop").slideUp();
});
// Drop down menu info
$("#doublePoints").hover(function() {
console.log("in");
//$(this).next(".shopHoverInfo").css("display", "block");
$(this).find(".shopHoverInfo").fadeIn();
}, function() {
console.log("out");
//$(this).next(".shopHoverInfo").css("display", "none");
$(this).find(".shopHoverInfo").fadeOut();
});
nav.shop {
width: 100%;
height: 100px;
background: #182024;
margin: 0;
}
nav.shop ul {
width: 960px;
list-style-type: none;
margin: 0 auto;
padding: 0;
}
nav.shop ul li {
display: inline-block;
vertical-align: top;
padding-left: 25px;
}
nav.shop ul li h1 {
font-size: 35px;
margin-right: 20px;
}
nav.shop ul li h2 {
color: #fff;
text-decoration: none;
font-size: 35px;
margin-left: 10px;
}
nav.shop ul li a {
color: #fff;
text-decoration: none;
font-size: 35px;
padding-bottom: 10px;
padding-top: 10px;
display: block;
}
.shopDrop {
position: absolute;
background: #182024;
padding: 30px 10px 0 10px;
margin-top: -30px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
nav.shop ul li div a {
font-size: 20px;
}
nav.shop ul li div span {
font-size: 15px;
}
#shopMultiplier {
border-bottom: 5px solid #CA2525;
}
#shopAutoclicker {
border-bottom: 5px solid #2596CA;
}
#shopFarms {
border-bottom: 5px solid #CAB125;
}
#shopSkills {
border-bottom: 5px solid #35CA25;
}
.shopHoverInfo {
display: none;
width: 150px;
background: #1C262A;
text-align: center;
padding: 0;
color: #fff;
}
.shopHoverInfo h3 {
font-size: 17px;
background: #CA2525;
margin: 0;
padding: 10px 5px 5px 5px;
border-top-right-radius: 10px;
border-top-left-radius: 10px;
}
.shopHoverInfo p {
font-size: 15px;
}
<nav class="shop">
<ul>
<li>
<h1>SHOP</h1></li>
<li>
<h2 href="#" id="shopMultiplier"><a href="#">Multiplier</a></h2>
<div class="shopDrop">
<a href="#" id="doublePoints">Double knowledge <span>☆</span><div class="shopHoverInfo">
<h3>Double Knowledge</h3>
<p>When you click you get 2x knowledge</p>
</div></a>
<a href="#" id="triplePoints">Triple knowledge <span>☆</span><div class="shopHoverInfo">
<h3>Triple Knowledge</h3>
<p>When you click you get 3x knowledge</p>
</div></a>
<a href="#" id="quadruplePoints">Quadruple knowledge <span>☆</span><div class="shopHoverInfo">
<h3>Quadruple Knowledge</h3>
<p>When you click you get 4x knowledge</p>
</div></a>
</div>
</li>
<li>
<h2 href="#" id="shopAutoclicker"><a href="#">Auto-clicker</a></h2></li>
<li>
<h2 href="#" id="shopFarms"><a href="#">Farms</a></h2>
<div class="shopDrop">
<a href="#" id="simpleminds">Simple mind's <span></span></a>
<a href="#" id="intelligentminds">intelligent mind's <span></span></a>
</div>
</li>
<li>
<h2 href="#" id="shopSkills"><a href="#">Skills</a></h2>
</li>
</ul>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>