jQuery在淡入淡出期间停止淡入淡出 [英] jQuery stop fadein during fadeout

查看:127
本文介绍了jQuery在淡入淡出期间停止淡入淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有此代码 :

$(".name").hover(
    function() { $(".kyle_hover").stop(true, true).fadeIn('slow'); },
    function() { $(".kyle_hover").stop(true, true).fadeOut('slow'); }
);

但是我彼此之间大约有4个,它们被隐藏并在悬停时出现,而在按预期离开时消失,但是.stop方法并没有发挥我的作用.

But I have about 4 of these on top of each other, they are hidden and appear when hovered and disappear when left as expected, but the .stop method isn't doing what I exepct.

当您快速将标题悬停在标题上时,它们会相互叠加(因为它们内置在HTML中),但是我希望动画在开始下一个标题之前完成,我是否误解了?

When you hover over the titles quickly, they all stack up on top of each other (as they are built into the HTML) but I want the animation to complete before starting the next one, have I misunderstood stop?

快速小提琴.

谢谢.

推荐答案

是的,您似乎误解了它. stop()不会清除所有动画的队列,它只是停止正在其调用的确切元素上正在进行的动画.因此,调用$(".kyle_hover").stop()将停止该特定元素的动画,但是如果将鼠标悬停在$("#gallery")上,其动画将被独立触发.

Yes, you seem to have misunderstood it. stop() doesn't clear the queue for all animations, it just stops the animation that's in progress on the exact element it's called on. So, calling $(".kyle_hover").stop() will stop this particular element's animation, but if you hover over $("#gallery"), its animation will be triggered independently.

在您的特定情况下,我只是将淡入/淡出元素放置在绝对位置,以免它们彼此堆叠.淡入/淡出看起来会更加令人愉悦,并且您的jQuery代码将不需要任何更改.

In your particular case, I'd just position the fading in/out elements absolutely so that they don't stack up one on above another. The fading in/out will look far more pleasing, and your jQuery code won't require any changes.

这篇关于jQuery在淡入淡出期间停止淡入淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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