我可以在jQuery中将.delay()和.animate()一起使用吗? [英] Can I use .delay() together with .animate() in jQuery?

查看:105
本文介绍了我可以在jQuery中将.delay()和.animate()一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码,该代码可在我正在工作的网站上以幻灯片形式打开购物篮预览.如果将鼠标悬停在它上面,它将保持打开状态,但是我希望它在触发悬停回调之前有两秒钟的延迟.这只是在用户不希望鼠标离开篮子区域的情况下.

I have this code, which slides open a basket preview on a website I am working on. It stays open if the user is hovered on it, but I want it to have a two second delay before the callback for my hover is triggered. This is just in case the user didn't want the mouse to leave the basket area.

以下是我用来制作篮子动画的代码:

Below is the code I am using to animate the basket:

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

这是我尝试使用的代码,但没有任何影响:

Here is the code I tried to use, but had no affect:

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

推荐答案

我一直在核心setTimeoutclearTimeout js函数的帮助下管理这类事情.

I've always managed this kind of things with the help of core setTimeout and clearTimeout js functions.

这是jsFiddle上的示例

Here is an example on jsFiddle

看看 jquery.hoverIntent插件,它也为您提供了一个悬停和超时事件超时

Take a look at jquery.hoverIntent plugin too, it gives you a timeout on hover and out events

这篇关于我可以在jQuery中将.delay()和.animate()一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆