栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

使用jquery 简单实现下拉菜单

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用jquery 简单实现下拉菜单

Jquery 是一个轻量的框架,个人认为非常好用,今天就写一个非常简单的例子,实现下拉菜单功能;

首先肯定要在页面引用jquery.js  版本不限 ;

接下来把=====================html贴出来:

复制代码 代码如下:
 
       

     
               
  • 系统管理
  •  
               
  • 干管所勤
  •  
               
  • 保护站
  •  
               
  • 木材检验
  •  
               
  • 森林管护
  •  
           
 
     
 
   
     
           
  • 出勤管理
  •  
           
  • 巡视管理
  •  
           
  • 现场取证
  •  
           
  • 问题处置
  •  
       
 
 
 
   
     
           
  • 位置监测
  •  
           
  • 检验管理
  •  
       
 
 
 
   
     
           
  • 出勤管理
  •  
           
  • 监管信息
  •  
       
 
 
 
   
     
           
  • 出勤管理
  •  
           
  • 监管信息
  •  
       
 
 
 
   
     
           
  • 权限管理
  •  
           
  • 设备管理
  •  
       
 
 

===========================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是也是获取高度,不过只包括文本高度 
        $(“#” + hideDivId).show(); 
        $(“#” + hideDivId).css(“left”, left); 
        $(“#” + hideDivId).css(“top”, top + height); 
    }, function() { 
        // 将原来的菜单隐藏 
        $(“.display”).hide(); 
    }); 

 
function initSubMenuHover() { 
    $(“.display”).hover(function() { 
        $(this).show(); 
    }, function() { 
        $(this).hide(); 
    }); 

 
function initSubMenuLiHover() { 
    $(“.redli”).hover(function() { 
        $(this).addClass(“redcolor”); 
    }, function() { 
        $(this).removeClass(“redcolor”); 
    }); 

效果如下:

小伙伴们使用的时候自己美化下,自由扩展下就可以用到自己的项目中了,我这里仅仅是简单做了点样式而已。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/104502.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号