Jquery, disable / ignore hover event during fade in / out?

戏子无情 提交于 2019-12-13 13:11:17

问题


I'm trying to figure out if this is possible.. I have an image map that does fade in / fade out based on hovers over certain parts.. the problem is that when the user hovers to a different area during the fade it finishes the fade it was doing then does the one for the area the mouse was moved to.. if the user moves quickly between a few different areas then the fades appear really jumpy and awkward, so I want to be able to disable the hover event (the fade) during the time that another fade is going on so it just ignores it..

I have thought about using some sort of delay but I don't know if this can work since I would think it would delay the fade too.. any advice is appreciated.


回答1:


I think you are referring to queue buildup problem there. Try using the stop method before the animation method eg:

$(...).stop().fadeIn();

More Info:

http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup

As for smooth animation, you can go for jQuery Easing Plugin.




回答2:


Without seeing your code, your tools are a mix of :animated and jQuerys .stop() method.

That could look like

$('imagemap').hover(function(){
   // only do something if no animation is in process (like fading)
   if(!$(this).is(':animated')){
   }
}, function(){
});

You might also call .stop(true, true) before any .fadeIn() in your chain. That will stop the current animation and jump to the end of the fx queue.

References: :animated selector, .stop(), .is()



来源:https://stackoverflow.com/questions/3328712/jquery-disable-ignore-hover-event-during-fade-in-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!