延迟后的jQuery slideUp [英] jQuery slideUp after delay

查看:82
本文介绍了延迟后的jQuery slideUp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航菜单子ul,当其父li悬停在鼠标上时会对其进行动画处理.当鼠标退出时,它也会向上滑动.但是,我正在尝试使其延迟1秒,然后才向上滑动.我希望孩子ul在鼠标离开后保持打开状态1秒钟.但是,它仍然立即滑上去.怎么了?

I have a navigation menu child ul animating when it's parent li is hovered with the mouse. It also slides up when the mouse exits. However, I am trying to get it to delay by 1 second before it slides up. I want the child ul to remain open for 1 second after the mouse leaves. However, it is still sliding up immediately. What's wrong here?

    $(".ipro_menu li>ul").hide(); // Hide all

$(".ipro_menu li").mouseenter(function() {
    $(this).children("ul").slideDown();
}).mouseleave(function() {
    $(this).delay(1000).children("ul").slideUp(); // Wait 1 sec before sliding up
});

推荐答案

顺序错误,请在延迟动画之前获取元素,否则延迟将应用于this,而不是子级.

Wrong order, get the elements before you delay the animation, otherwise the delay is applied to this, not it's children.

$(this).children("ul").delay(1000).slideUp();

这篇关于延迟后的jQuery slideUp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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