我决定采用一种更复杂的方法来编写菜单。看来我喜欢折磨自己。
无论如何,我创建了一个 div 菜单:
<div class="menu-bar">
<div class="menu-item"><span class="menu-text">HOME</span></div>
<div class="menu-item"><span class="menu-text">ABOUT US</span>
<div class="sub-menu-items">
<div class="sub-menu-item">History</div>
<div class="sub-menu-item">Mission, vision and values</div>
<div class="sub-menu-item">B-BBEE</div>
<div class="sub-menu-item">Team</div>
<div class="sub-menu-item">Professional Affiliations</div>
</div>
</div>
<div class="menu-item"><span class="menu-text">SECTORS</span></div>
<div class="menu-item"><span class="menu-text">SERVICES</span></div>
<div class="menu-item"><span class="menu-text">CSR</span></div>
<div class="menu-item"><span class="menu-text">PROJECTS</span></div>
<div class="menu-item"><span class="menu-text">SUSTAINABILITY</span></div>
<div class="menu-item"><span class="menu-text">CONTACT US</span></div>
</div>
我的问题来自子菜单.sub-menu-items
。一旦鼠标移出“关于我们”块并进入子菜单,我不知道如何使其保持打开状态。
这是我拥有的当前 Javascript 代码:
$('.sub-menu-items').hide();
$('.menu-text').hover(function(e) {
// Show highlight
$(this).toggleClass('menu-text-hover');
$(this).parent().toggleClass('menu-item-hover');
if($(this).html().indexOf('ABOUT',0) !== -1)
$('.sub-menu-items').show('fast');
},function(e) {
// Hide highlight
$(this).toggleClass('menu-text-hover');
$(this).parent().toggleClass('menu-item-hover');
if($(this).html().indexOf('ABOUT',0) !== -1)
$('.sub-menu-items').hide('fast');
});
这是我的CSS:
.menu-bar { position:absolute; top:159px; height:54px; width:1024px; background-color:#fafafa; z-index:2; }
.menu-item { display:table-cell; vertical-align:middle; position:relative; left:79px; height:54px; text-align:center; width:105px; border-right:dotted thin #000; border-bottom:dotted thin #000; background-color:#fafafa; }
.menu-item-hover { border-bottom:none; }
.menu-text { display:table-cell; vertical-align:middle; height:52px; width:101px; position:relative; left:2px; top:1px; text-align:center; border-top-right-radius:0px; margin-left:2px; margin-top:2px; margin-right:2px; }
.menu-text-hover { border-top-right-radius:20px; background-color:#445921; color:#fff; cursor:pointer; }
.sub-menu-items { position:absolute; display:inline-block; top:55px; width:105px; background: rgba(255, 255, 255, 0.8); font-size:12px; z-index:100; }
.sub-menu-item { background:url(../images/devider-horizontal.png) no-repeat center top; display:block; height:40px; }
.sub-menu-item:last { background-image:none; display:block; height:40px; }
任何人都可以帮助我实现当鼠标仍然悬停在下拉菜单上时使下拉菜单保持可见的目标吗?