【问题标题】:Mobile Navigation hide/show one button移动导航隐藏/显示一键
【发布时间】:2014-07-18 21:23:04
【问题描述】:

您好,我有导航,它在单击按钮时显示和隐藏。我知道我可以在隐藏的 div 中添加一个按钮来关闭它。但是,我希望显示相同的按钮并隐藏相同的 div。有什么想法吗?我尝试颠倒#hide 和#show,但它随后隐藏了原件。

小提琴:http://jsfiddle.net/6xtd8/1/

    <div id="mobnavz"><a id="show">MENU</a>
</div> 
    <div class="target" style="display:none;" id="hide">
        <div id="mobnav">
         <ul>
                <li>Home Security</li>
                <li>Home Automation</li>
                <li>Business Security</li>
                <li>Business Automation</li>
            </ul>
</div>
</div>
     $(document).ready(function () {
         // This hides the Nav
         $("#hide").click(function () {
             $(".target").hide("slide", {
                 direction: "up"
             }, 500);
             $('#show').show();
             $('#hide').hide();
         });
         // This shows nav when button is clicked.
         $("#show").click(function () {
             $(".target").show("slide", {
                 direction: "up"
             }, 500);
             $('#show').hide();
             $('#hide').show();
         });
         // This animated the toggle.
         if ($('.target').is(':visible')) {}
     });

【问题讨论】:

    标签: javascript jquery html css toggle


    【解决方案1】:

    如果我理解正确的话.. 您想在单击同一个按钮时打开和关闭一个部门。试试这个:

     $(document).ready(function () {
    
         $("#show").click(function () {
             $("#hide").slideToggle(500);           
         });
         // This animated the toggle.
         if ($('.target').is(':visible')) {}
     });
    

    【讨论】:

    • 很高兴能帮上忙。如果能解决问题,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多