我可以在jQuery中同时使用.delay()和.animate()吗?

我可以在jQuery中同时使用.delay()和.animate()吗?,jquery,jquery-animate,delay,Jquery,Jquery Animate,Delay,我有这段代码,它可以在我正在工作的网站上打开一个篮子预览。如果用户将鼠标悬停在它上面,它将保持打开状态,但我希望它在触发我的鼠标悬停回调之前有两秒钟的延迟。这只是为了防止用户不希望鼠标离开篮区 下面是我用来设置篮子动画的代码: $('.cart_button, .cart_module').hover(function(){ $(".cart_module").stop().animate({top:'39px'},{duration:500}); }, function(){

我有这段代码,它可以在我正在工作的网站上打开一个篮子预览。如果用户将鼠标悬停在它上面,它将保持打开状态,但我希望它在触发我的鼠标悬停回调之前有两秒钟的延迟。这只是为了防止用户不希望鼠标离开篮区

下面是我用来设置篮子动画的代码:

$('.cart_button, .cart_module').hover(function(){
    $(".cart_module").stop().animate({top:'39px'},{duration:500});
}, function(){
    $('.cart_module').stop().animate({top: -cartHeight},{duration:500})
});
以下是我尝试使用但没有效果的代码:

$('.cart_button, .cart_module').hover(function(){
    $(".cart_module").delay().animate({top:'39px'},{duration:500});
}, function(){
    $('.cart_module').delay().animate({top: -cartHeight},{duration:500})
});

我总是在核心
setTimeout
cleartimout
js函数的帮助下管理这类事情

这是一个


再看看,它会给你一个悬停和退出事件的超时时间,你希望它延迟多长时间

$('.cart_button, .cart_module').hover(function(){
            $(".cart_module").delay(2000).animate({top:'39px'},{duration:500}); //two seconds
        }, function(){
            $('.cart_module').delay(2000).animate({top: -cartHeight},{duration:500}) //two seconds 
    });

如果您在延迟之前添加停止,它工作正常:

$('.cart_button, .cart_module').hover(function() {
    $('.cart_module').stop(true, true).delay(100).animate({top:'39px'}, 400);
  },
  function() {
    $('.cart_module').stop(true, true).animate({top: -cartHeight}, 250);
});

看起来自2011年以来,jQuery可能已经有过类似的更新。在Chrome中,我可以使用以下sans超时调用:

$('.thing').hover(function(){
    $(".thing").delay(2000).animate({top:'39px'},{duration:500});
}

版本1.4.2。没有发生任何事情,只是没有延迟,我将在我的问题中添加我试图使用的代码。可能重复…我忘记输入延迟的时间,但设置时间仍然没有任何区别。
$('.thing').delay(2000).animate({top:'39px'},500)(略短的版本)