使用jquery 简单实现下拉菜单

2020-05-22 16:18:53易采站长站整理

    <ul> 
        <li class=”redli”>权限管理</li> 
        <li class=”redli”>设备管理</li> 
    </ul> 
</div> 

===========================css样式:

/**头部菜单**/ 
.header_menu{ 
    float:right; 
    width: 50%; 
    height: 100%; 
    cursor: pointer; 

.header_menu ul{ 
    list-style: none; 
    height: 100%; 

.header_menu ul li{ 
    float: right; 
    width: 20%; 
    color:white; 
    font-size:14px; 
    padding-top: 55px; 
    font-weight: bold; 

.display{ 
    display: none; 

.display ul{ 
    list-style: none; 
    width: 100px; 

.display ul li{ 
    padding-top:10px; 
    padding-bottom: 5px; 
    padding-left:5px; 
    cursor: pointer; 
    font-size: 14px; 

.movediv{ 
    position: fixed; 
    left: 0px; 
    top:0px; 
    font-size: 14px; 
    white; 
    border:1px solid white; 

.redcolor{ 
    #a0c9e6; 

=======================js脚本

$(function() { 
    // 菜单绑定事件 
    initMenuListener(); 
    // 下拉菜单绑定事件 
    initSubMenuHover(); 
    // 下拉菜单颜色改变 
    initSubMenuLiHover(); 
}); 
/**
 * 头部菜单绑定滑过事件
 */ 
function initMenuListener() { 
    $(“.menuli”).hover(function() { 
        var hideDivId = $(this).attr(“id”) + “_div”; 
        // 得到菜单的位置 
        var left = $(this).offset().left; 
        var top = $(this).offset().top; 
        var height = $(this).outerHeight();//outerHeight是获取高度,包括内边距,height是也是获取高度,不过只包括文本高度