jQuery fadeIn CSS 类
我正在尝试对某些具有“button”类的对象执行简单的 fadeIn() CSS 类。我想在悬停时淡入“hoverbutton”类,然后在鼠标离开该项目时淡出。
我在问题中发现了这一点。它似乎工作得很好,直到我注意到当我将鼠标悬停在多个按钮上时,有些按钮很快就会卡在“悬停按钮”类上。不知道如何解决这个问题。任何建议都会很棒。
$('.button').hover(function(){
$(this).addClass('hoverbutton', 200);
}, function(){
$(this).removeClass('hoverbutton', 200);
});
当我将鼠标悬停在一个项目上并在第一个项目的淡入淡出完成之前快速跳转到该类的另一个项目时,它们似乎被卡住了。
stop()ing 产生相同的结果。悬停类仍然卡住
$('.button').hover(function(){
$(this).stop().addClass('hoverbutton', 200);
}, function(){
$(this).stop().removeClass('hoverbutton', 200);
});
I'm trying to do simple fadeIn() CSS class on certain objects that have the "button" class. I want to fadeIn the "hoverbutton" class on hover and then fadeOut when their mouse leaves the item.
I found this in the questions. It seemed to work well until i noticed when i hover over multiple buttons quickly some get stuck on the "hoverbutton" class. Not a clue how to fix that. Any suggestions would be great.
$('.button').hover(function(){
$(this).addClass('hoverbutton', 200);
}, function(){
$(this).removeClass('hoverbutton', 200);
});
it seems they get stuck when i hover over one and quickly jump to another item with that class before the fading on the first one is complete.
stop()ing produced the same result. hover class still gets stuck
$('.button').hover(function(){
$(this).stop().addClass('hoverbutton', 200);
}, function(){
$(this).stop().removeClass('hoverbutton', 200);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
问题是因为 jQueryUI 使用
style
属性来执行动画,如果它没有完成(因为悬停在悬停完成之前发生),则它的动画类不会实际上已添加,因此无法通过悬停来删除。要解决此问题,我们需要在悬停时执行两件事:
addClass()
动画,addClass()
动画创建的任何临时样式,就像这样。这
是一个示例:http://jsfiddle.net/RBTT8/
The problem is because jQueryUI is using the
style
property to do the animation, and if it doesn't complete (because the hover-out occurs before hover-in finishes) the class it's animating to isn't actually added, and so can't be removed by the hover-out.To fix this, we need to do two things on the hover-out:
addClass()
animationaddClass()
animationLike so..
Here's an example: http://jsfiddle.net/RBTT8/
尝试停止动画队列:
Try stopping the animation queue:
查看 stop() 的文档。您可以将其添加到您的呼叫中,如下所示:
Check out the documentation for stop(). You would add it to your call like so:
实现相同效果的另一种方法是使用 CSS3 过渡,一切都支持Internet Explorer 除外(最高版本 10)。
这是一个示例: http://jsfiddle.net/3yr8G/
An alternative approach to achieve the same effect would be to use CSS3 Transitions, supported in everything except Internet Explorer (up to version 10).
Here's an example: http://jsfiddle.net/3yr8G/
尝试使用 CSS add --
到您需要淡入
w3schools 过渡链接的元素:
http://www.w3schools.com/css/css3_transitions.asp
Try using CSS add --
to the element u need to fade in
w3schools transition link:
http://www.w3schools.com/css/css3_transitions.asp