Javascript JQuery淡出发生在错误的时间

Javascript JQuery淡出发生在错误的时间,javascript,jquery,css,fadeout,Javascript,Jquery,Css,Fadeout,我有以下代码: $(document).ready(function () { $("#full-btns").children().delay(4000).fadeOut("slow"); $('#full-btns').hover(function() { $('#full-btns').children().stop().animate({opacity:'100'}); $('#full-btns').children().show(); }, functi

我有以下代码:

$(document).ready(function () {

$("#full-btns").children().delay(4000).fadeOut("slow");

$('#full-btns').hover(function() {
      $('#full-btns').children().stop().animate({opacity:'100'});
      $('#full-btns').children().show();

}, function() {
        $("#full-btns").children().fadeOut("slow");

});
加载页面时,
#完整BTN
元素在淡出之前显示4000ms。我遇到的问题是,如果用户在
#full btns
元素仍然可见时将鼠标悬停在该元素上,它会导致该元素淡出,因为
$(“#full btns”).children().fadeOut(“slow”)在悬停时被调用。我希望
#将鼠标悬停在全BTN上时始终可见

加载页面时,将鼠标悬停在红色div上,注意它是如何淡出的。这是不可取的。当鼠标悬停在红色div上时(当其可见时),它应该保持可见

更新:
(现在包括解决方案)

如果我没有误解这个问题,你就不能
返回false在悬停调用结束时防止事件冒泡



使用setInterval和clearInterval

$('#full-btns').hover(function() {

      clearInterval(refreshIntervalId);        
      $('#full-btns').children().stop().animate({opacity:'100'});
      $('#full-btns').children().show();

}, function() { 
        $("#full-btns").children().fadeOut("slow");            
});

var refreshIntervalId = setInterval(function() {
     $("#full-btns").children().fadeOut("slow");
}, 4000);

在任何人悬停之前,您只需清除所有动画

$("#full-btns").children().delay(4000).fadeOut("slow");

    $('#full-btns').hover(function() {
        $('#full-btns').children().stop(true, true);  // Stop the fade-out animation
          $('#full-btns').children().stop().animate({opacity:'100'});
          $('#full-btns').children().show();

    }, function() {
        console.log('fadeOout called');
            $("#full-btns").children().fadeOut("slow"); 


    });​


注意:当你第一次悬停并且(在你的代码中)div消失时,这不是因为$(“#满BTN”).children().fadeOut(“慢”)但因为它刚刚完成您应用的早期动画。[您的第1行]。

delay()方法最适合在排队的jQuery效果之间进行延迟。例如,由于它的局限性,它没有提供取消延迟的方法-。延迟()不是JavaScript本机setTimeout函数的替代品,后者可能更适合某些用例。您能将HTML与JS一起显示吗?您真的需要查看HTML吗?上面的注释来自jQuery的.delay()文档。所以,如果你在那里有一个stop()也没关系。由于您使用的是.delay(),因此它仍将淡出。您考虑过使用setTimeout()吗?这样你就可以用clearTimeout()取消超时了。谢谢,我会试试的。不过,我认为还有另一个问题,悬停导致在悬停函数中调用.fadeout-请参阅问题更新谢谢您的回答-我不确定这会解决我的问题。请参阅我的JSFIDDLE更新,可能是我没有正确理解这个问题。但对我来说[我的代码]和[正确答案]给出了相同的结果。无论如何,thanx。