简体   繁体   中英

Close responsive menu on pageload

I created a responsive navigation menu, but for some reason I can't get it to start out closed.

If you look at the website here http://riprap.pdslo.com and re-size your screen to a phone or tablet size, then hit refresh you will see that it is open on page load.

Here is the code if anyone would like to take a stab at it and try to get the menu to close on page load. (I apologize for the code dump, just not sure where I went wrong.)

I would greatly appreciate any help.

-----HTML Code-----

<nav id="menu-wrap">    
    <ul id="menu">
<li><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/#">Home</a></li>
<li>bla bla</li>


    </ul>
</nav>

-----JS Code-----

        <script type="text/javascript">
$(function() {
        if ($.browser.msie && $.browser.version.substr(0,1)<7)
        {
        $('li').has('ul').mouseover(function(){
            $(this).children('ul').css('visibility','visible');
            }).mouseout(function(){
            $(this).children('ul').css('visibility','hidden');
            })
        }

        /* Mobile */
        $('#menu-wrap').prepend('<div id="menu-trigger">Menu</div>');       
        $("#menu-trigger").on("click", function(){
            $("#menu").slideToggle();
        });

        // iPad
        var isiPad = navigator.userAgent.match(/iPad/i) != null;
        if (isiPad) $('#menu ul').addClass('no-transition');      
 });      
 </script>

-----CSS Code-----

#menu-wrap{display:none;}




    /* Mobile */
    #menu-trigger {
        display: none;
    }




        #menu .top-list{display:none;}
        /* nav-wrap */
        #menu-wrap {
            position: relative;
    display:none;
        }

        #menu-wrap * {
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }

        /* menu icon */
        #menu-trigger {
            display:none; /* show menu icon */
            height: 45px;
            line-height: 45px;
            cursor: pointer;            
            color: #FFFFFF;
            font-weight: 700;
            background-color: #063346;
            text-align:center;
            font-family:"Bitter",sans-serif;
            font-size:24px;

        }

        /* main nav */
        #menu {
            margin: 0;
            position: relative;
            width: 100%;
            z-index: 1;
            background-color: #034A68;
            display: block;
            box-shadow: none;       
        }

/*      #menu:after {
            content: '';
            position: relative;
            left: 25px;
            top: -8px;
            border-left: 8px solid transparent;
            border-right: 8px solid transparent;
            border-bottom: 8px solid #444;
        }*/ 

        #menu ul {
            position: relative;
            visibility: visible;
            opacity: 1;
            margin: 0;
            background: none;
            box-shadow: none;               
        }

        #menu ul ul {
            margin: 0 0 0 20px !important;
            box-shadow: none;       
        }

        #menu li {
            position:relative;
            display: block;
            float: none;
            border: 0;
            box-shadow: none;
            width:100%;         
        }

        #menu ul li{
            margin-left: 20px;
            box-shadow: none;       
        }

        #menu a{
            border-top: 1px solid #063346;
            color: #FFFFFF;
            display: block;
            float: none;
            padding: 10px 0;
            text-align: center;
            text-decoration: none;
        }

        #menu a:hover{
            color: #FFFFFF;
            background:#045072;
        }   

        #menu ul a{
            padding: 0;
            width: auto;        
        }

        #menu ul a:hover{
            background: none;   
        }

        #menu ul li:first-child a:after,
        #menu ul ul li:first-child a:after {
            border: 0;
        }       


@media only screen and (min-width: 768px) and (max-width: 959px) {
    #menu-wrap{display:block;}


        #menu .top-list{display:none;}


    /* Mobile */
    #menu-trigger {
        display: block;
    }

    }



@media only screen and (max-width: 767px) {
    #menu-wrap{display:block;}


        #menu .top-list{display:block;}


    /* Mobile */
    #menu-trigger {
        display: block;
    }

}

In line 140 (the last part) of the css you have to add following:

#menu { display:none; }

So the menu is hidden in the beginning on screens lower than 767px.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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