简体   繁体   English

jQuery FadeIn / fadeOut无法正常运行

[英]jquery fadeIn/fadeOut not functioning properly

I have several divs that I want to have fade in and out depending on a nav panel. 我有几个div,我希望根据导航面板进行淡入和淡出。 I am running into an issue with two of the divs, but the others work fine so I am not sure what is happening. 我遇到了两个div的问题,但是其他div都工作正常,所以我不确定发生了什么。

here is the jQuery code, here the two divs that are wacky have been singled out, the real code generalizes it to work for all divs: 这是jQuery代码,这里挑出了两个古怪的div,真正的代码将其概括为适用于所有div:

    $('#behind_the_lens').click(function() {
                          $('#gallaries-page').fadeOut(0);
                          $('#behind_the_lens-page').fadeIn(750);
                          $('#pricing-page').fadeOut(750);
                         });
    $('#pricing').click(function() {
                          $('#pricing-page').fadeIn(750);
                          $('#behind_the_lens-page').fadeOut(750);
                         });

When the first function runs #pricing-page just hides, no fading and #behind_the_lens-page does fade. 当第一个函数运行时, #pricing-page只会隐藏,不会褪色,并且#behind_the_lens-page不会褪色。

When the second function runs #pricing-page waits for #behind_the_lens-page to fade out, then it instantly shows. 当第二个函数运行时, #pricing-page等待#behind_the_lens-page淡出,然后立即显示。

this does not happen for any other combination of divs so it is very strange to me. 这对于div的任何其他组合都不会发生,所以对我来说很奇怪。

as for the contents of these divs, one #pricing-page uses a table and the other uses a floating layout. 至于这些div的内容,一个#pricing-page使用一个表格,另一个使用浮动布局。 but there layouts types are not unique from other divs. 但那里的布局类型并不是其他div唯一的。

In summary, why is it working this way for these divs but not the others? 总而言之,为什么它对这些div起作用而不对其他div起作用? furthermore, why is it doing this at all? 此外,为什么要这么做呢?

Edit: was able to come up with a fiddle here that shows the problem. 编辑:能够提出一个小提琴在这里显示问题。

You are fading in and fading out simultaneously. 您正在同时渐入渐出。 Watch the scrollbar, your "clicked" page is appearing as the currently visible is disappearing, and jumps up into position after the visible completely disappears (display:none). 观看滚动条,您的“已单击”页面将随着当前可见项的消失而显示,并在可见项完全消失后跳到适当位置(显示:无)。

Use the complete callback on fadeOut so that fading in happens after fading out finishes. 在fadeOut上使用完整的回调,以便在淡出完成后进行淡入。

https://jsfiddle.net/u3u8jsqr/2/ https://jsfiddle.net/u3u8jsqr/2/

JS JS

if (thisID != visibleID) {
    $(visibleID).fadeOut(750, function () {
        $(thisID).fadeIn(750);
    });                                
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM