使导航栏切换隐藏/显示

时间:2018-11-09 06:41:55

标签: javascript jquery css responsive-design toggle

在使用javascript和CSS @media时遇到了一些麻烦。我已经制作了汉堡图标并使其具有响应能力。但是当我单击图标导航栏时看不到?关于这个问题,我真的很感谢任何帮助!

HTML

<div class="gnav clearfix" id="myTopnav">
                <h1><a href="index.html"><img src="images/index/logo.gif" width="236" height="75" alt="株式会社ジェイウィル J-WILL CORPORATION"></a></h1>

                <ul class="ul_menu" class="clearfix" >
                    <li><a href="index.html"><img src="images/common/gnav01.gif" width="111" height="38" alt="HOME"></a></li>
                    <li>
                        <a href="company/index.html"><img src="images/common/gnav02.gif" width="100" height="38" alt="企業情報"></a>
                        <ul class="sub_list sub01">
                            <li><a href="company/index.html">代表ご挨拶</a></li>
                            <li><a href="company/index.html#sc02">行動指針</a></li>
                            <li><a href="company/index.html#sc03">企業概要</a></li>
                        </ul>
                    </li>
                </ul>
                <span class="nav-toggle"><a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa fa-bars" style="color: white; font-size: 30px;"></i></a></span>
            </div>

CSS

@media only screen and (max-width: 591px) {
    .nav-toggle {
        display: block;
    }

}



@media only screen and (max-width: 590px) {
    .gnav {
        float: left;
        width: 100% !important;
        background-color: #1e2d68;
    }

    .gnav.responsive {position: relative;}
    .gnav.responsive .icon {
        position: absolute;
        right: 0;
        top: 0;
  }
    .gnav.responsive li {
        float: none;
        display: block;
        text-align: left;
  }

    .sub_list {
        position: static;
    } 
}

@media screen and (min-width: 799px) {
    .ul_menu {
        display: block !important;
    }
}

JS

<script>
        function myFunction() {
            var x = document.getElementById("myTopnav");
            if (x.className === "gnav") {
                x.className += " responsive";
            } else {
                x.className = "gnav";
            }
        }
</script>

我认为错误的部分是我与JS切换的连接。但是我做不正确。您对解决此问题有任何建议吗?如果您需要任何更新或难以理解,请告诉我,我会解释更多细节。

0 个答案:

没有答案