html导航栏上下滑动效果,JQuery实现导航栏上下滑动效果

本文介绍如何使用JQuery实现二级导航菜单的上下滑动效果。通过mouseenter和mouseleave事件,确保鼠标在二级菜单移动时背景稳定,提供更好的用户体验。文中给出了JQuery、CSS和HTML代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文采用嵌套的ul、li代码实现二级导航菜单,并实现导航菜单栏的背景具有上下滑动的效果,注意此处鼠标悬停效果采用的是mouseenter和mouseleave,这对函数可以保证当鼠标在二级菜单移动时,导航菜单的背景不变化,如果采用mouseover和mouseout,鼠标在二级菜单移动一次,导航菜单背景就会上下滑动一次,用户体验差,大家可以自行修改代码观看效果,现将三部分代码贴入:

-----------------JQuery代码---------------------------

$(function(){

$(".navcon ul li").mouseenter(function(){

$(this).children("a").children(".out").stop(true,true).slideUp();

$(this).children("a").children(".over").stop(true,true).slideDown();

$(this).children("ul").show();

});

$(".navcon ul

li").mouseleave(function(){

$(this).children("a").children(".over").stop(true,true).slideUp();

$(this).children("a").children(".out").stop(true,true).slideDown();

$(this).children("ul").hide()

});

})

-----------------JQuery代码---------------------------

-----------------CSS样式---------------------------

div, ul, li, a,

span {

margin:0;

padding:0;

}

.nav .navcon ul {

height:40px;

width:100%;

}

.over {

background-color:#9F9;

}

.out {

background-color:#CFF;

}

.navcon ul li {

float:left;

width:100px;

height:40px;

list-style-type:none;

margin-left:3px;

line-height:40px;

text-align:center;

}

.navcon ul li a {

display:block;

width:100px;

height:40px;

overflow:hidden;

}

.navcon ul li a span {

display:block;

height:40px;

width:100px;

}

.navcon ul li ul {

display:none;

}

.navcon ul li ul li {

left:0;

}

-----------------CSS样式---------------------------

-----------------HTML代码---------------------------

a4c26d1e5885305701be709a3d33442f.png

-----------------HTML代码---------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值