为什么不在添加类时隐藏它,因为fadeOut(0) 没有动画
$('#header #menu li a').hover(function () {
$(this).hide().addClass('hover').fadeIn(300);
},
function () {
$(this).hide().removeClass('hover').show();
// as there is no fading time the line above will be equal to
$(this).removeClass('hover');
});
当您在动画完成后需要完成某些事情时,您应该使用回调$(...).fadeIn(400,function(){ alert('this is the callback'); },如果您不使用回调,则代码会在动画进行时运行。
而且我不知道它是否有用但是:hovercss中有一个伪类,请参见here
所有主流浏览器都支持 :hover 伪类。
所以有了这个你可以做各种各样的事情,比如:
#header #menu li a:hover { ...set style of 'a' when over 'a' }
#header #menu li:hover a { ...set style of 'a' when over 'li' }
稍微玩一下,你可以用 css 做很多事情