jQuery实现下拉菜单的实例代码


Posted in jQuery onJune 19, 2017

基本效果是这样的~~

jQuery实现下拉菜单的实例代码

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      list-style: none;
    }
    .wrap {
      width: 330px;
      height: 30px;
      margin: 100px auto 0;
      padding-left: 10px;
      background-color: skyblue;
    }
    .wrap li {
      background-color: skyblue;
    }
    .wrap > ul > li {
      float: left;
      margin-right: 10px;
      position: relative;
    }
    .wrap a {
      display: block;
      height: 30px;
      width: 100px;
      text-decoration: none;
      color: #000;
      line-height: 30px;
      text-align: center;
    }
    .wrap li ul {
      position: absolute;
      top: 30px;
      display: none;
    }
  </style>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
  <script>
    $(function () {
      //获取所有li,添加移入事件
      $(".wrap>ul>li").mouseenter(function () {
        //设置内部的子元素ul slideDown
        $(this).children("ul").stop().slideDown(600);
      });
      //移出li时,让内部子元素slideUp
      $(".wrap>ul>li").mouseleave(function () {
        $(this).children("ul").stop().slideUp(600);
      });
      //如果当前运动没有完毕,又添加了新的动画,这时新的动画需要等待当前动画执行完毕才会开始
      //如果持续添加。一定会造成动画的积累,这种情况我们称为动画队列
    });
  </script>
</head>
<body>
<div class="wrap">
  <ul>
    <li>
      <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单1</a>
      <ul class="ul">
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单11</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单12</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单13</a></li>
      </ul>
    </li>
    <li>
      <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单2</a>
      <ul>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单21</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单22</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单23</a></li>
      </ul>
    </li>
    <li>
      <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >一级菜单3</a>
      <ul>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单31</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单32</a></li>
        <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >二级菜单33</a></li>
      </ul>
    </li>
  </ul>
</div>
</body>
</html>

以上所述是小编给大家介绍的jQuery实现下拉菜单的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

jQuery 相关文章推荐
jquery中each循环的简单回滚操作
May 05 jQuery
jquery操作ul的一些操作笔记整理(干货)
Aug 31 jQuery
jQuery基于cookie实现换肤功能实例
Oct 14 jQuery
jQuery实现标签子元素的添加和赋值方法
Feb 24 jQuery
jQuery创建及操作xml格式数据示例
May 26 jQuery
jQuery实现的简单获取索引功能示例
Jun 04 jQuery
使用jquery模拟a标签的click事件无法实现跳转的解决
Dec 04 jQuery
jquery实现垂直无限轮播的方法分析
Jul 16 jQuery
jQuery实现的图片点击放大缩小功能案例
Jan 02 jQuery
jquery实现的放大镜效果示例
Feb 24 jQuery
Jquery+javascript实现支付网页数字键盘
Dec 21 jQuery
jQuery实现tab栏切换效果
Dec 22 jQuery
jquery DataTable实现前后台动态分页
Jun 17 #jQuery
jQuery Jsonp跨域模拟搜索引擎
Jun 17 #jQuery
jQuery 控制文本框自动缩小字体填充
Jun 16 #jQuery
jQuery序列化后的表单值转换成Json
Jun 16 #jQuery
基于jQuery和CSS3实现APPLE TV海报视差效果
Jun 16 #jQuery
利用jquery去掉时光轴头尾部线条的方法实例
Jun 16 #jQuery
jQuery实现 RadioButton做必选校验功能
Jun 15 #jQuery
You might like
使用sockets:从新闻组中获取文章(一)
2006/10/09 PHP
php使用smtp发送支持附件的邮件示例
2014/04/13 PHP
Yii的CDbCriteria查询条件用法实例
2014/12/04 PHP
php中Ioc(控制反转)和Di(依赖注入)
2017/05/07 PHP
laravel框架模型中非静态方法也能静态调用的原理分析
2019/11/23 PHP
PHP pthreads v3下worker和pool的使用方法示例
2020/02/21 PHP
Yii 实现数据加密和解密
2021/03/09 PHP
jQuery 动画基础教程
2008/12/25 Javascript
js 点击按钮弹出另一页,选择值后,返回到当前页
2010/05/26 Javascript
javascript图片预加载完整实例
2015/12/10 Javascript
jQuery实现的placeholder效果完整实例
2016/08/02 Javascript
详解nodeJs文件系统(fs)与流(stream)
2018/01/24 NodeJs
JS监听滚动和id自动定位滚动
2018/12/18 Javascript
[07:48]DOTA2上海特级锦标赛主赛事首日RECAP
2016/03/04 DOTA
tensorflow1.0学习之模型的保存与恢复(Saver)
2018/04/23 Python
对python的bytes类型数据split分割切片方法
2018/12/04 Python
使用python切片实现二维数组复制示例
2019/11/26 Python
Python Pandas 转换unix时间戳方式
2019/12/07 Python
PyTorch 普通卷积和空洞卷积实例
2020/01/07 Python
tensorflow保持每次训练结果一致的简单实现
2020/02/17 Python
python多维数组分位数的求取方式
2020/03/03 Python
5行Python代码实现图像分割的步骤详解
2020/05/25 Python
css3中新增的样式使用示例附效果图
2014/08/19 HTML / CSS
css 如何让背景图片拉伸填充避免重复显示
2013/07/11 HTML / CSS
HTML5 Canvas+JS控制电脑或手机上的摄像头实例
2014/05/03 HTML / CSS
骆驼官方商城:CAMEL
2016/11/22 全球购物
自考生毕业自我鉴定
2013/10/10 职场文书
写自荐信的七个技巧
2013/10/15 职场文书
大四毕业生学习总结的自我评价
2013/10/31 职场文书
前台文员职责范本
2014/03/07 职场文书
奥运会口号
2014/06/13 职场文书
学生意外伤害赔偿协议书
2014/09/17 职场文书
计划生育诚信协议书
2014/11/02 职场文书
教师党员学习十八届四中全会思想汇报
2014/11/03 职场文书
政审证明材料
2015/06/19 职场文书
SQL实现LeetCode(176.第二高薪水)
2021/08/04 MySQL