jQuery animations: fadeIn() hidden div, not showing content

五迷三道 提交于 2019-12-07 13:35:15

问题


I have a button with the id of "start_game" that has an attached click function and a callback to fade the button out, and then fade in a div that is currently set by css to display:none.

When I click the button, I see that the outer container div that holds all of this expands as if to make room for the div that is to be displayed, however I never see the content that I have inside of it.

Here is the current code:

$("#start_game").click(function () {
        $(this).fadeOut();
        $(".input-append").fadeIn();
    });

and the html

<div class="hero-unit">
        <div id="container">
            <p>Shall we?</p>
            <button class="btn-primary btn-large" id="start_game">Play!</button>
            <div class="input-append hidden">
                <p>How many players?</p>
                <input class="span2" id="appendedInputButton" type="text" />
                <button class="btn" type="button">Go!</button>
            </div>
        </div>
    </div>

here is the only custom css, the other css file is twitter bootstrap

.hidden {
display: none;
}

Now I have tried numerous approaches. I have tried fadeIn, I've tried chaining together a few different combinations of show() or hide() or toggle() or fadeToggle(). I have also tried attaching to the callback an iteration of all the child elements of the hidden div and doing fadeIn() one by one on them, nothing seems to be working.

I am testing in Google Chrome 26 and IE10.

Thanks for any help!


回答1:


I just ran into the same scenario. If I mark a twitter bootstrap control group hidden initially and then use show() method the outer div of the control group it is indeed shown but the contents of that control group div are still hidden.

The reason for that is bootstrap CSS looks for .hidden class to add visibility CSS rules to the inner divs as well, but the JQuery show() method does not remove the hidden class. It manipulates the CSS directly leaving the hidden class in place.

You can use removeClass('hidden') to remedy that problem.

Now the bonus question: how do we animate that transition??

And the answer is: fadeIn().removeClass('hidden'); Not very intuitive but hey, it works :)




回答2:


Try this

$("#start_game").click(function () {
    $(this).fadeOut();
    $(".input-append").fadeIn("slow").removeClass('hidden');
});


来源:https://stackoverflow.com/questions/16006100/jquery-animations-fadein-hidden-div-not-showing-content

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