jQuery实现二级导航菜单的示例

实用JQ实现导航二级菜单效果,导航菜单在网站中非常常见,有的网站可能会出现三级菜单及多级菜单模式,下面我们来简单的实现一个二级菜单的效果。

部分效果截图:

整体代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>导航菜单案例</title>
		<style>
			*{
				padding: 0;
				margin: 0;
			}
			ul,li{
				list-style: none;
			}
			a{
				text-decoration: none;
			}
			nav{
				width: 1140px;
				height: 40px;
				margin: 0 auto;
				border:solid 1px #CCC;
				position: relative;	

			}
			nav ul li{
				width: 150px;
				line-height: 40px;
				float: left;
			}
			nav ul li a{
				display: block;
				width: 100%;
				float: left;
				color: #444;
				font-size: 14px;
				text-align: center;
			}
			nav>ul>li:hover{
				background: #f5f5f5;
			}
			nav ul li ul{
				display: none;
				width: 150px;
				position: absolute;
				background-color: #f5f5f5;
				overflow: hidden;
				top:41px;
			}
			nav ul li ul li{
				float: left;
				border-bottom: solid 1px #CCC;
			}
			nav ul li ul li:last-child{
				border: none;
			}
			nav>ul>li>ul>li:hover a{
				background-color: #444;
				color: #FFF;
			}
		</style>
	</head>
	<body>
		<br />
		<br />
		<nav>
			<ul>
				<li><a href="" title=" 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" 首页">首页</a></li>
				<li><a href="" title=" 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" 联系我们">联系我们</a></li>
				<li><a href="" title=" 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" 在线留言">在线留言</a></li>
				<li>
					<a href="" title=" 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" 新闻资讯">新闻资讯</a>
					<ul>
						<li><a href="" title=" 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" 国内资讯">国内资讯</a></li>
						<li><a href="" title=" 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" 国内资讯">国内资讯</a></li>
					</ul>
				</li>
				<li>
					<a href="" title=" 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" 产品中心">产品中心</a>
					<ul>
						<li><a href="" title=" 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" 除雪机">除雪机</a></li>
						<li><a href="" title=" 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" 运雪车">运雪车</a></li>
					</ul>
				</li>
				<li><a href="" title=" 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" 案例展示">案例展示</a></li>
			</ul>
		</nav>
		<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
		<script>
			var $li = $("nav > ul > li");
	   	$li.mouseenter(function () {
		$(this).children("ul").stop().slideDown();
    	});
    	$li.mouseleave(function () {
     		$(this).children("ul").stop().slideUp();
     	});	

		</script>
	</body>
</html>

以上就是jQuery实现二级导航菜单的示例的详细内容,更多关于jQuery实现二级导航菜单的资料请关注我们其它相关文章!

(0)

相关推荐

  • jquery实现具有收缩功能的垂直导航菜单

    本文介绍一种比较常见的导航菜单是如何实现的,它具有垂直结构,点击导航主标题可以展开或者折叠二级菜单. 代码实例如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <title>垂直导航菜单</title> <style type="text/css"> body{ margin:0; padding:0 0 12px 0

  • jQuery+css实现非常漂亮的水平导航菜单效果

    本文实例讲述了jQuery+css实现非常漂亮的水平导航菜单效果.分享给大家供大家参考,具体如下: 运行效果截图如下: 用到的背景图片tab.gif如下: 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="

  • jQuery+CSS3实现仿花瓣网固定顶部位置带悬浮效果的导航菜单

    本文实例讲述了jQuery+CSS3实现仿花瓣网固定顶部位置带悬浮效果的导航菜单.分享给大家供大家参考,具体如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml

  • jQuery+CSS实现一个侧滑导航菜单代码

    侧滑菜单在网站设计中应用比较广泛,在许多网站上都可以看到此种类型的菜单.它可以展示重点信息,使其更有可读性和美观性,满足用户体验价值! 今天小编给大家展示如何使用jquery和css实现侧滑菜单. 效果展示      源码下载 为了建立导航菜单,让我们先看看html结构: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title&g

  • 基于jQuery实现火焰灯效果导航菜单

    效果描述为:当鼠标经过某一导航选项的时候,后面的背景图片(上图"圣诞节"后圆角背景)会弹性缓动到该导航选项,如果没有发生单击动作,鼠标移开后,背景图又回到原来的位置. 您可以狠狠地点击这里:demo效果页面 使用说明: 1.需要链接的文件 需要调用的文件有:jQuery库(1.2以上版本),jQuery缓动插件(jquery.easing.min.js),火焰灯效果插件(jquery.lavalamp.min.js)以及一个ul li列表的样式文件.例如,本demo实例页面链接如下截图

  • 原生js和jquery分别实现横向导航菜单效果

    本文实例为大家分享了原生js和jquery横向导航菜单的制作方法,供大家参考,具体内容如下 原生javascript实现: 这一次要实现的是鼠标放上去以后,菜单栏被选中的那一栏水平拉伸,鼠标离开后水平收缩.并带有一定的时间性,使肉眼能够看出其拉伸收缩的动画效果. 开始用javascript进行编写: 首先在之前水平方向的导航栏上进行操作,将第一栏和选中栏的样式只改变为背景变黑色,文字变白色 .on,a:hover{background:#000000;color:#FFFFFF;} 之后开始写j

  • jQuery实现简单漂亮的Nav导航菜单效果

    本文实例讲述了jQuery实现简单漂亮的Nav导航菜单效果.分享给大家供大家参考,具体如下: 自己写的一个简单的导航菜单,先看效果: 鼠标悬浮时菜单项向上移动成蓝底白字,点击之后底部会有蓝条表示当前选中项. 页面代码,菜单的每一项都是一个 div ,其中包括一个 ul 用来放置显示文字等,另一个 div 则是底部的蓝条,需要给第一项和最后一项设置不同的 class ,样式需要用到: <div id="nav"> <div class="navItem ind

  • 基于jQuery实现以手风琴方式展开和折叠导航菜单

    本章节分享一段代码实例,它实现了手风琴方式展开和折叠导航菜单效果. 代码实例如下: 代码实例如下: <!DOCTYPE html> <html> <head> <meta charset="gb2312"> <meta name="author" content="http://www.jb51.net/" /> <title>我们</title> <sty

  • jQuery和CSS仿京东仿淘宝列表导航菜单

    以前看着京东,淘宝的导航做的真好,真想哪一天自己也能做出来这么漂亮功能全的导航菜单.今天弄了一下午终于自制成功,主要使用jQuery和CSS,实现功能基本和京东一样. 功能介绍: 1.鼠标停留导航: 2.根据子列表的高度,自动调整对齐方式(顶端对齐/父类目对齐): 3.父子类目样式一致. 功能截图: 源代码: <html> <head> <meta http-equiv="Content-Type" content="text/html; cha

  • jQuery纵向导航菜单效果实现方法

    本文实例讲述了jQuery纵向导航菜单效果实现方法.分享给大家供大家参考,具体如下: 效果如下: 核心代码如下: $( document ).ready( function(e){ var $catCont = $( ".cat-cont" ); //二级菜单div var $catList = $( ".J_Cat" ); //一级菜单li $catList.on( "mouseenter", function(){ var index = $

  • jQuery模仿京东/天猫商品左侧分类导航菜单效果

    现在天猫或者京东商品分类模块的默认的效果是这样的: 当鼠标滑过任意一栏导航分类时,就会出现相关详细分类模块,例如: 当鼠标移出蓝色框以外的区域,就会恢复默认的效果显示!然而使用jQuery的鼠标滑过事件,用得比较多的就是mouseover()和mouseout(),或者是他们两个的整合hover();所以之前我也是用的这种方法,但是一直调整都调整不到想要的效果!后来灵光一现,想着使用一下mouseenter()和mouseleave();结果分分钟想要的效果就出来了! 我的布局大致是这样的: <

随机推荐