Jquery 停止淡入/淡出
这是一个相当简单的问题,但我似乎无法弄清楚。
基本上我有一个jquery悬停,它在悬停时淡入一个div并淡出另一个。
当我快速悬停几次时,它会来回脉冲大约 3-4 秒以完成所有淡入/淡出。
我通常用 .stop() 来停止这些事情,但它在这里似乎不起作用。如果我将鼠标悬停在 an`$(".txtWrap").stop().hover( 之前的按钮上,如何消除淡入效果
$(".txtWrap").stop().hover(
function () {
$(this).find('.txtBock').fadeOut();
$(this).find('.txtDesc').fadeIn();
},
function () {
$(this).find('.txtBock').fadeIn();
$(this).find('.txtDesc').fadeOut();
}
)
This is a fairly easy one, but I cant seem to figure it out.
Basically I have a jquery hover that fades in a div and fades out the other upon hover.
When I quickly hover on and off a few times it pulses back and forth for about 3-4 seconds to finish all those fade in/fade outs.
I generally stop these things with .stop(), but it doesnt seem to do the trick here. How can I kill the fade in if I hover off the button before the an`$(".txtWrap").stop().hover(
$(".txtWrap").stop().hover(
function () {
$(this).find('.txtBock').fadeOut();
$(this).find('.txtDesc').fadeIn();
},
function () {
$(this).find('.txtBock').fadeIn();
$(this).find('.txtDesc').fadeOut();
}
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的
stop()
放错地方了。试试这个:
编辑:
这将动画元素的不透明度而不隐藏元素。如果您希望它们隐藏,请使用
.hide()
您需要向 animate 函数添加回调。Your
stop()
is misplaced.Try this:
EDIT:
This will animate the elements' opacity without hiding the element. If you want them hidden, use
.hide()
you'll need to add a callback to the animate function.我想我会发布这个,因为这些答案都不适合我。
*真正的参数告诉 stop 清除队列并转到动画末尾
链接:http://forum.jquery.com/topic/jquery-hover-events-cant-keep-up-with-fadein-and-fadeout-events-queue
Thought I would post this because none of these answers worked for me.
*The true params tell stop to clear the queue and go to the end of the animation
Link: http://forum.jquery.com/topic/jquery-hover-events-cant-keep-up-with-fadein-and-fadeout-events-queue
在这种时候,我求助于 Brian Cherne 的天才
.hoverIntent()
插件 -- 非常流畅...等到用户放慢足够的速度后再执行。您可以根据您的需要进行配置。只需包含插件(它足够短,有时我会将其直接放入我的脚本文件中),然后添加单词
Intent
:In times like this I turn to Brian Cherne's genius
.hoverIntent()
plugin -- It's quite smooth...waits until the user has slowed down enough before executing. You can configure it to your needs.Just include the plugin (it's short enough I'll sometimes place it directly into my script file) then add the word
Intent
:当超级智能的 SO 搜索引擎为我突出显示这个问题时,我正要发布类似的问题,所以我想我应该为后代发布我自己的解决方案。
我采用了 user113716 的解决方案并对其进行了充实。就我而言,我隐藏和显示的 div 最初是
display:none
,因此我必须向 CSS 添加opacity:0
并告诉 jQuery 设置 < code>.css({display:block}) 在它开始将不透明度动画设置为1
淡入之前。在淡出时,我不需要它,但我确实添加了将不透明度动画为零后对 div 的
.hide()
的回调。这是一个小提琴,说明了我最终得到的结果:
http://jsfiddle.net/mblase75/wx2MJ/
相关的JavaScript:
I was about to post a similar question when the superintelligent SO search engine highlighted this question for me, so I thought I'd post my own solution for posterity.
I took user113716's solution and fleshed it out a bit. In my case, the div I was hiding and showing started out as
display:none
, so I had to addopacity:0
to the CSS and tell the jQuery to set.css({display:block})
before it started animating the opacity to1
to fade in.On the fade out, I didn't need that, but I did add a callback to
.hide()
the div after animating the opacity to zero.Here's a fiddle illustrating what I ended up with:
http://jsfiddle.net/mblase75/wx2MJ/
The relevant JavaScript:
如果你有这个东西:
好吧,你必须使用这个指令来重置fadeIn或队列中的其他事件:
If you have this thing:
all right, you must use this instruction to reset fadeIn or other event in queue: