Jquery悬停切换

时间:2011-01-10 21:29:19

标签: jquery menu hover jquery-animate

我所做的就是在document.load上我已经减少了导航器的高度并且动画了导航器下方的div。我想要做的是在导航中的每个li的悬停是反向下面的动画jquery代码:

              $('.tabs li a').animate({
                height: '40'
              }, 1000, function() {
                // Animation complete.
              });

              $('#tabs-wrap').animate({
                marginTop: '-=147'
              }, 1000, function() {
                // Animation complete.
              });

如何使用悬停触发器来反转此代码?

由于

2 个答案:

答案 0 :(得分:5)

如下所示?

$('tabs li a').hover(function(){
  $(this).animate({height:40}, 1000, function(){
      //animation complete
  });
}, function(){
  $(this).animate({height:0}, 1000, function(){
      //animation complete
  });  
});

$('#tabs-wrap').hover(function(){
  $(this).animate({marginTop: '-147'}, 1000, function(){
   //animation complete   
  });

}, function(){
  $(this).animate({marginTop: '147'}, 1000, function(){
   //animation complete
  });

});

注意,除了这样的动画之外,请记住在继续播放元素上的另一个动画之前停止动画。

示例:

$(this).stop().animate({height:300}), 1000, function(){ });

答案 1 :(得分:0)

如果我做对了,你正在寻找.hover()功能,不是吗?

相关问题