html导航栏切换,jQuery实现简单导航栏的样式切换

style css样式部分:

ul{

margin: 0 auto;

height: 50px;

background-color: #369;

}

ul>li{

text-decoration: none;

display: inline-block;

height: 50px;

line-height: 50px;

color: #fff;

padding: 0 15px;

border-left: 1px solid #365;

}

.active,ul>li:hover{

background-color: #fff;

color: #369;

cursor: pointer;

}

html部分:

  • 首页
  • 关于我们
  • 产品中心
  • 新闻中心
  • 关于我们

方法一:https://www.jkys120.com/article/95498/

$li = $('ul>li');

// console.log($li);

$li.bind('click',function(){

$this=$(this);

$this.addClass('active');

$this.siblings().removeClass('active');

console.log('111');

});https://www.jkys120.com/article/95498/

方法二:(原生Js)

for(let i = 0 ;i < navs.length; i++){

navs[i].onclick = function(e){

let activedNav = this.parentNode.querySelector('.active');

if(activedNav == this){

return;

}

activedNav.className = '';

this.className = 'active';

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值