【发布时间】:2017-05-12 16:55:31
【问题描述】:
我正在使用物化 css,在导航栏上我有一个下拉菜单,鼠标悬停在更垂直的图标上时会打开(在右侧的示例中)。
当我点击下拉菜单中的链接时,目标会正确触发,但下拉菜单不会关闭。
工作example here。我希望下拉菜单在单击后自动关闭。在我的html代码下面:
<ul id="dropdown1" class="dropdown-content collection">
<li><a href="#/" onclick="openGFS(event, '1', '1'); return false;" id="defaultOpenGFS">Item 1</a></li>
<li><a href="#/" onclick="openGFS(event, '2', '2'); return false;" id="defaultOpenGFS">Item 2</a></li>
</ul>
<nav class="blue darken-3">
<div class="nav-wrapper">
<ul id="tabs" class="left">
<li><a href="#" onclick="openGFS(event, '1', '1'); return false;" id="defaultOpenGFS" class="yellow-text text-accent-3"><b>Item 1</b></a></li>
<li><a href="#" onclick="openGFS(event, '2', '2'); return false;" class="yellow-text text-accent-3"><b>Item 2</b></a></li>
</ul>
<ul class="right">
<li><a class="dropdown-button" href="#!" data-activates="dropdown1"><i class="material-icons tiny">more_vert</i></a></li>
</ul>
</div>
</nav>
<div id="1" class="tabcontent_gfs">
content 1 here
</div>
<div id="2" class="tabcontent_gfs">
content 2 here
</div>
这里是javascript
(function($) {
$(function() {
$('.dropdown-button').dropdown({
inDuration: 300,
outDuration: 225,
hover: true, // Activate on hover
belowOrigin: true, // Displays dropdown below the button
alignment: 'right' // Displays dropdown with edge aligned to the left of button
}
);
}); // End Document Ready
})(jQuery); // End of jQuery name space
var currentTabGFS = null;
function openGFS(evt, tabName, ThirdValue) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent_gfs");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
var text = document.getElementById(tabName);
text.innerHTML = text.innerHTML.replace('{var}',tabName);
currentTabGFS = tabName;
}
document.getElementById("defaultOpenGFS").click();
function dismissGFS(){
document.getElementById(currentTabGFS).style.display='none';
};
以及部分css:
<style class="cp-pen-styles">
.dropdown-content {
background-color: #FFFFFF;
margin: 0;
display: none;
min-width: 350px;
height: 120px;
max-height: auto;
margin-left: -1px;
overflow: auto;
opacity: 0;
position: absolute;
white-space: nowrap;
z-index: 1;
will-change: width, height;
}
</style>
【问题讨论】:
标签: javascript html css materialize