当用户点击或悬停汉堡包菜单时,我遇到了关于弹出菜单内容的问题。 Angular是我的应用程序的基础,我有一些在视图javascript和css,以使这个工作,但没有得到理想的结果。我的截图显示了这个角落:
<!doctype html>
<html ng-app="mbapp">
<head>
<meta charset="utf-8">
<title>Cloud + Enterprise // Moneyball Tools</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css({.tmp/serve,src}) styles/vendor.css -->
<!-- bower:css -->
<!-- run `gulp inject` to automatically populate bower styles dependencies -->
<!-- endbower -->
<!-- endbuild -->
<!-- build:css({.tmp/serve,src}) styles/app.css -->
<!-- inject:css -->
<!-- css files will be automatically insert here -->
<!-- endinject -->
<!-- endbuild -->
<base href="/">
<link href="app/styles/mbapp.css" rel="stylesheet" />
<style type="text/css">
li > .sideCont > a {
text-decoration: none;
}
li > .sideCont > li a: hover {
text-decoration: none;
color: inherit;
}
.menu_items_toggle {
opacity: 1 !important;
top: 100% !important;
}
#menu {
position: relative;
}
#menu_items {
position: absolute;
top: 0%;
opacity: 0;
transition: all 0.5s;
}
.menu_items_toggle {
opacity: 1 !important;
top: 100% !important;
}
</style>
</head>
<body style="background-color: #f5faff;">
<div class="container-fluid" style="font-family: Segoe UI; padding: 0;">
<div id="menu" style="background-color: #002F33; min-height:50px;">
<span id="span_img_container" class="navIcon" style="width: 50px; border-right-style: solid 1px #939393;"><img id="menu_img" src="assets/images/icon_hamburger.png"></span>
<div id="menu_items">
<a href="https://www.moneyball.ms/">Moneyball Website</a>
<br>
<a href="https://www.tools.moneyball.ms/">Moneyball Tool</a>
<br>
<a href="https://msit.microsoftstream.com/channel/8a4a7740-855b-4c52-912c-c97fb714a0a6">Moneyball Stream Channel</a>
<br>
</div>
<span style="color: #ffffff; font-size: 22px; padding-left:20px; padding-top: 21px;">Moneyball Tool</span>>
</div>
<div class="col-md-2 tabNav">
<ul class="tabTitle">
<p>Project tools</p>
<li class="tabCont"><a href="#/home">Welcome</a></li>
<li class="tabCont"><a href="#">Experiments</a></li>
<li class="tabCont"><a href="#">Interview Notes</a></li>
</ul>
<ul class="tabTitle">
<p>Hypothesis worksheets</p>
<li class="tabCont"><a href="/#/steps">Problem phase</a></li>
<li class="tabCont"><a href="/#/solutionHyp">Solution phase</a></li>
<li class="tabCont"><a href="#">Service phase</a></li>
<li class="tabCont"><a href="#">Growth phase</a></li>
</ul>
</div>
<div ui-view>
</div>
</div>
<script type="text/javascript">
//make a refernce to the container that holds all your links
var menu_item_container = document.getElementById("menu_items")
//This function will show/hide menu options if image is clicked on
function clicker() {
menu_item_container.classList.toggle('menu_items_toggle');
console.log(menu_item_container.classList.contains('menu_items_toggle'))
}
console.log(document.getElementById("span_img_container"));
document.getElementById("menu_img").addEventListener('click', clicker)
</script>
<!-- build:js(src) scripts/vendor.js -->
<!-- bower:js -->
<!-- run `gulp inject` to automatically populate bower script dependencies -->
<!-- endbower -->
<!-- endbuild -->
<!-- build:js({.tmp/serve,.tmp/partials,src}) scripts/app.js -->
<!-- inject:js -->
<!-- js files will be automatically insert here -->
<!-- endinject -->
<!-- inject:partials -->
<!-- angular templates will be automatically converted in js and inserted here -->
<!-- endinject -->
<!-- endbuild -->
</body>
</html>
答案 0 :(得分:1)
问题是您的菜单位于&#34;汉堡包菜单上方#34;。
发生这种情况是因为唯一不可点击的元素是那些设置为display: none;
或pointer-events: none;
的元素。
您可以按照以下方式解决此问题:
#menu_items.menu_items_toggle {
opacity: 1;
top: 100%;
display: inline-block;
}
注意我是如何将id(#menu_items)添加到选择器中,以便在不添加!important
的情况下提高CSS选择器的特异性。
要使用menu_items样式,您必须添加display: none;
。
#menu_items {
position: absolute;
top: 0%;
opacity: 0;
transition: all 0.5s;
display: none;
}