我知道这非常简单,但我已经编写和重写了这个函数一个小时,但没有成功:
单击时,我想将“活动”添加到单击的链接中,并从导航栏中<li>
的所有其他链接中删除“活动” 。<li>
HTML:
<nav>
<ul>
<li><a href="http://0327ea8.netsolhost.com/#home" class="home">Home</a></li>
<li><a href="http://0327ea8.netsolhost.com/blog/" class="blog">Blog</a></li>
<li><a href="http://0327ea8.netsolhost.com/#catalog" class="catalog">Catalog</a></li>
<li><a href="http://0327ea8.netsolhost.com/#authors" class="authors">Authors</a></li>
<li><a href="http://0327ea8.netsolhost.com/#store" class="store">Store</a></li>
</ul>
</nav>
jQuery:
// NAVBAR ADD ACTIVE
$("nav ul li a").click(function(){
$("nav ul li").removeClass('active');
$(this).stop().animate();
$(this).parent().addClass('active');
});
这可以很好地添加类,但我无法将其删除。
我也尝试将它分成单独的功能,但没有运气。
我在那里有 .stop().animate() 因为我在链接的悬停状态上有一个 .animate() 。
谢谢!
编辑:
这是悬停的 jQuery,也是我拥有 .stop().animate() 的原因
$("nav ul li a, aside ul li.categories a, div.posts div.foot a").hover(function(){
$(this).animate({'backgroundColor' : '#edf5e9'}, 200);
},function() {
$(this).animate({'backgroundColor' : '#ccd4c8'}, 600);
});
我不确定为什么 .stop().animate() 是错误的。如果我没有 .animate() ,则活动类不会粘住,如果有,活动类会粘住。
我仍然无法删除课程:-/