jquery最终停止工作

时间:2011-07-19 17:17:38

标签: jquery

我正在制作一个带有以下脚本的下拉菜单,下拉效果会影响前几个鼠标悬停,但随后停止工作,任何想法?谢谢!

$(document).ready(function(){  

    $("ul.topnav li").hover(function() { 
        $(this).children().fadeIn(800); 
    },
    function() { 
        $(this).find("ul.subnav").stop().fadeOut(800);
    }) 

});  

2 个答案:

答案 0 :(得分:1)

问题是过早地中断fadeInfadeOut。执行此操作时,该项目将获得新的“基线”不透明度。 fadeIn不会淡化为1的不透明度,它会淡化到基线(例如,如果您的元素最初的不透明度为.8,并且您隐藏它,fadeIn将会淡化到.8不是1)。

要解决此问题,请使用不透明度为1而不是fadeTo的{​​{1}}。

编辑:找到我以前的一个答案,用一个更彻底的解释用小提琴来说明这个想法。 jQuery's stop() seems to be blocking animations that haven't been queued yet

答案 1 :(得分:-1)

我认为选择是错误的。如果你在ul.topnav li的孩子们褪色,那么我想你想要褪去同一个孩子。

   $(document).ready(function(){  

      $("ul.topnav > li").hover(function() { 
            $(this).children().fadeIn(800); 
      },
       function() { 
        $(this).children().stop().fadeOut(800);
      }) 

});