jQuery,仅当页面加载淡入结束时悬停才处于活动状态
我是 jQuery 的初学者!
我需要一些 div 在页面加载时淡入,我可以做到。 我需要让它们以不同的延迟和时间显示,我可以做到。 每个 div 都有一个图像,当您将鼠标悬停在相对的 div 上时,该图像会淡入,我可以做到。
问题是,如果 div 的淡入未结束,则悬停时图像的动画仍会开始。
我希望如果用户将鼠标悬停在仍然带有 fadeIn 的 div 上,则不会发生任何事情。 如果您将鼠标悬停在完全显示的 div 上,则图像将开始淡入。
这是我的 HTML
<div id="immagine1">
<img src="images/logo_key_css.png" alt="logo_key_css" width="169" height="53"/>
</div>
<div id="immagine2">
<img src="images/logo_key_css.png" alt="logo_key_css" width="169" height="53"/>
</div>
这是我的 jQuery
$(window).load(function () {
$('#immagine1').hide();
$('#immagine1').stop().fadeIn(1000);
$('#immagine2').hide();
$('#immagine2').stop().delay(2500).fadeIn(2500);
$('div').hover(
function(){ $(this).find('img').fadeIn(1000);
});
});
和 img css
img{
display:none;
}
我如何“禁用”悬停效果直到页面加载时淡入结束?
谢谢!
I'm pretty a beginner with jQuery!
I need to have some divs to fadeIn on page loads, and i can do it.
I need to have them showing with different delay and times, and i can do it.
Every div has an image that fadeIn when you hover the relative div, and i can do it.
The problem is that the animation of the image on hover, start still if the fadeIn of the div is not ended.
I want that if the user hover the div that is still going with fadeIn nothing happens.
If you hover a div that is totally show then the image starts the fadeIn.
Here is my HTML
<div id="immagine1">
<img src="images/logo_key_css.png" alt="logo_key_css" width="169" height="53"/>
</div>
<div id="immagine2">
<img src="images/logo_key_css.png" alt="logo_key_css" width="169" height="53"/>
</div>
Here is my jQuery
$(window).load(function () {
$('#immagine1').hide();
$('#immagine1').stop().fadeIn(1000);
$('#immagine2').hide();
$('#immagine2').stop().delay(2500).fadeIn(2500);
$('div').hover(
function(){ $(this).find('img').fadeIn(1000);
});
});
And the img css
img{
display:none;
}
How can i "disable" the hover effect till the end of the fadeIn on page load?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信这会满足您的需求。基本上,您需要做的是等到
完全淡入,然后再绑定图像的悬停事件。您可以通过在
回调 中执行事件绑定来实现此目的div> 淡入。此外,由于您只在悬停事件(而不是悬停事件)上执行某些操作,因此您可以使用 .mouseenter() 而不是 .hover()
这是代码:
这是它的工作演示: http://jsfiddle.net/vYz3t/
I believe that this will do what you are looking for. Basically, what you need to do is wait until the
<div>
has faded in completely before you bind the hover event for the image. You can achieve this by doing the event binding in the callback for the<div>
fadeIn. Additionally, since you are only doing something on the hoverIn event (and not on hoverOut), you can use .mouseenter() instead of .hover()Here is the code:
And here's a working demo of it: http://jsfiddle.net/vYz3t/
看,我不明白你真正的问题,但试试这个:
或者看看jQuery悬停文档
Look, i doesn't understand your real problem, but try this:
Or take a look on jQuery hover docs
我不确定您想要实现什么,但也许您可以通过使用
获得所需的效果.queue()
将悬停动画显式放置在队列末尾:淡入效果将在默认队列(“fx”)中的待处理动画完成后开始。这是演示这个概念的小提琴;也许它会为你指明正确的方向。
I'm not sure what you're trying to achieve, but maybe you can get your desired effect by using
.queue()
to explicitly place the hover animation at the end of the queue:The fade-in effect will begin after pending animations in the default queue ("fx") are complete. Here's a fiddle demonstrating the concept; perhaps it will point you in the right direction.