html二级菜单移动下划线效果,jQuery CSS3导航菜单下划线动画特效

js代码

var nav = $('nav');

var line = $('

line.appendTo(nav);

var active = nav.find('.active');

var pos = 0;

var wid = 0;

if(active.length) {

pos = active.position().left;

wid = active.width();

line.css({

left: pos,

width: wid

});

}

nav.find('ul li a').click(function(e) {

if(!$(this).parent().hasClass('active')) {

e.preventDefault();

var _this = $(this);

nav.find('ul li').removeClass('active');

var position = _this.parent().position();

var width = _this.parent().width();

if(position.left >= pos) {

line.animate({

width: ((position.left - pos) + width)

}, 300, function() {

line.animate({

width: width,

left: position.left

}, 150);

_this.parent().addClass('active');

});

} else {

line.animate({

left: position.left,

width: ((pos - position.left) + wid)

}, 300, function() {

line.animate({

width: width

}, 150);

_this.parent().addClass('active');

});

}

pos = position.left;

wid = width;

}

});

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值