java导航菜单_[Java教程]jQuery 简单的导航菜单

[Java教程]jQuery 简单的导航菜单

0 2015-12-24 09:00:06

自己写的一个简单的导航菜单,先看效果:

bc91bb04e6e9c61e24c974e4440db8f2.gif

鼠标悬浮时菜单项向上移动成蓝底白字,点击之后底部会有蓝条表示当前选中项。

页面代码,菜单的每一项都是一个 div ,其中包括一个 ul 用来放置显示文字等,另一个 div 则是底部的蓝条,需要给第一项和最后一项设置不同的 class ,样式需要用到:

bc91bb04e6e9c61e24c974e4440db8f2.gif

bc91bb04e6e9c61e24c974e4440db8f2.gif

样式,主要就是每个菜单项的左右边框的设置以及 ul 和 li 的位置设置:

bc91bb04e6e9c61e24c974e4440db8f2.gif

*{ padding: 0; margin: 0;}body{ background-color: #fffff3; font: 12px/1.6em Helvetica, Arial, sans-serif;}ul,li{ list-style: none;}#nav{ text-align: center; height: 50px; font-size: 10px; line-height: 30px; background-color: #F0E6DB; margin-bottom: 10px;}.navItem{ cursor: pointer; position: relative; float: left; width: 100px; height: 50px; font-size: 15px; border-right: 2px solid rgb(255,255,255); border-left: 2px solid rgb(255,255,255); overflow: hidden; font-weight:bold;}.indexNavItem{ border-left: 4px solid rgb(255,255,255); margin-left: 10px;}.lastNavItem{ border-right: 4px solid rgb(255,255,255);}.logoutNavItem{ float: right; width: 120px; margin-right: 10px; border-left: 4px solid rgb(255,255,255);}.navUl{ position: relative; height: 100px; width: 100%; border-bottom: 5px solid rgb(2,159,212);}.navUl li{ height: 50px; line-height: 50px;}.highlighter{ position: absolute; bottom: 0; height: 5px; width: 100%;}.selectedNav{ background-color: #029FD4;}.hoverLi{ background-color: #029FD4; color: #ffffff;}

bc91bb04e6e9c61e24c974e4440db8f2.gif

接下来就是给菜单编写悬浮和单击事件的 js 代码了,悬浮时将 ul 上移 li 的高度,鼠标移开后再恢复,点击之后就是给蓝条的 div 添加样式即可:

bc91bb04e6e9c61e24c974e4440db8f2.gif

$(function() { $(".navItem").hover(function() { $(this).children("ul").animate({ top: "-50px" }, 100); }, function() { $(this).children("ul").animate({ top: "0px" }, 100); }); $(".navItem").click(function(event) { $(this).siblings().children('.highlighter').removeClass('selectedNav'); $(this).children('.highlighter').addClass('selectedNav'); });})

bc91bb04e6e9c61e24c974e4440db8f2.gif

本文网址:http://www.shaoqun.com/a/171421.html

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。

jquery

0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值