jQuery,仅当页面加载淡入结束时悬停才处于活动状态

发布于 2024-09-27 01:36:33 字数 1043 浏览 2 评论 0原文

我是 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!

This is the test page

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

习惯成性 2024-10-04 01:36:33

我相信这会满足您的需求。基本上,您需要做的是等到

完全淡入,然后再绑定图像的悬停事件。您可以通过在 回调 中执行事件绑定来实现此目的div> 淡入。此外,由于您只在悬停事件(而不是悬停事件)上执行某些操作,因此您可以使用 .mouseenter() 而不是 .hover()

这是代码:

$(function() {
    $('div img').hide();
    $('#immagine1').hide().fadeIn(5000, function() {
        $('div').mouseenter(function() {
            $(this).find('img').fadeIn('1000');
        });
    });
});

这是它的工作演示: 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:

$(function() {
    $('div img').hide();
    $('#immagine1').hide().fadeIn(5000, function() {
        $('div').mouseenter(function() {
            $(this).find('img').fadeIn('1000');
        });
    });
});

And here's a working demo of it: http://jsfiddle.net/vYz3t/

轻许诺言 2024-10-04 01:36:33

看,我不明白你真正的问题,但试试这个:

$(window).load(function () {
    $('#immagine1, #immagine2').hide();
    $('#immagine1').hover(
            function(){
                $(this).fadeIn(1000);
            },
            function(){
                $(this).fadeOut(1000);
            }
    );
    $('#immagine2').hover(
            function(){
                $(this).fadeIn(1000);
            },
            function(){
                $(this).fadeOut(1000);
            }
   );
});

或者看看jQuery悬停文档

Look, i doesn't understand your real problem, but try this:

$(window).load(function () {
    $('#immagine1, #immagine2').hide();
    $('#immagine1').hover(
            function(){
                $(this).fadeIn(1000);
            },
            function(){
                $(this).fadeOut(1000);
            }
    );
    $('#immagine2').hover(
            function(){
                $(this).fadeIn(1000);
            },
            function(){
                $(this).fadeOut(1000);
            }
   );
});

Or take a look on jQuery hover docs

心在旅行 2024-10-04 01:36:33

我不确定您想要实现什么,但也许您可以通过使用 获得所需的效果.queue() 将悬停动画显式放置在队列末尾:

$('div').hover(function() {
  $(this).queue(function() {
    $(this).find('img').fadeIn(1000);
  });
});​

淡入效果将在默认队列(“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:

$('div').hover(function() {
  $(this).queue(function() {
    $(this).find('img').fadeIn(1000);
  });
});​

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文