一款简单好看的jQuery+css3线性流体导航菜单动画特效,鼠标点击导航菜单项下划线流动动画代码。
js代码
<script>
var nav = $('nav');
var line = $('<div />').addClass('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;
}
});</script>
系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791