单击页面链接一次,导航/汉堡包图标消失

时间:2017-02-14 08:34:51

标签: javascript html css

我正在设计一个单页滚动网站。当我在屏幕宽度小于780像素的情况下点击导航栏中的页面链接时(当汉堡包图标出现时),汉堡包图标消失。除非我刷新页面,否则我无法取回它。单击页面链接一次后,导航栏也会以全屏宽度消失。我想随时查看汉堡图标和顶部导航。我用来折叠显示在780px的全屏菜单的JavaScript导致了这个问题,但我需要它,或者点击链接时菜单不会消失。感谢任何可以提供帮助的人!



$(document).ready(function() {
    $('a').click(function() {
        $('#menu').slideToggle();
    });
});

@media screen and (max-width: 780px) {

    nav {
        width: 100%;
        margin: 0;
        padding: 0;
        position: relative;
        left: 0;
        display: block;
        opacity: 1.0 !important;
        filter: alpha(opacity=100); /* For IE8 and earlier */
    }

    nav ul {
        width: 100%;
        margin: 0 auto;
        padding: 0;
        display: none;
        float: none;
    }

    nav ul li {
        font-size: 1.3em;
        font-weight: normal;
        line-height: 40px;
        width: 100% !important;
        margin: 0;
        padding: 0;
    }

    nav ul li:nth-of-type(1) { margin-top: 20%; }

    nav ul li:hover { background: #565758; }
    
    nav ul li a {
        color: white !important;
        font-family: "Lato", sans-serif;
        border-bottom: none !important;
        display: inline-block;
    }

    nav ul li a.active-link {
        color: white !important;
        font-size: 1.3em;
    }

    nav ul li a:hover {
        color: white;
        width: 100%;
    }
        
    /*Display 'show menu' link*/
    .show-menu {
        margin: 0 !important;
        padding: 1em !important;
        text-align: right;
        display: block;
        float: right;
    }

    /*Show menu when invisible checkbox is checked*/
    input[type=checkbox]:checked ~ #menu { background-color: #747475 !important; display: block; height: 100vh; }
}​

<header>
    <nav>
        <label for="show-menu" class="show-menu"><img src="hamburger.png" alt="Hamburger Menu Icon" style="width: 15%;"></label>
        <input type="checkbox" id="show-menu" role="button">
        <ul id="menu">
            <li><a href="#choco">HOME</a>
            <li><a href="#about-page">ABOUT</a></li>
            <li><a href="#portfolio-page">PORTFOLIO</a></li>
            <li><a href="#contact.html">CONTACT</a></li>
        </ul>
    </nav>
    <div id="logo"><img src="logo-grey.png" alt="Logo" style="max-width:100%; height:auto;"></div>
</header>​
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您还需要将切换添加到复选框。它是一个jQuery函数,它使用特定的动画和样式。

<%
String uploadPath="D:\\upload\\";
int size=10*1024*1024;

try{
    MultipartRequest multi=new MultipartRequest(request,uploadPath,size,"UTF-8", new DefaultFileRenamePolicy());

    Enumeration params=multi.getParameterNames();

    while(params.hasMoreElements()){

    }

    }   catch(FileNotFoundException e){
            e.printStackTrace();
    }   finally {

    }


%>

修改

我添加了一个工作示例。我没有在这里使用切换,以获得更好的设计。现在菜单也点击了复选框: - )

&#13;
&#13;
$('#show-menu').click(function() {
    $('#menu').slideToggle();
});
&#13;
$(document).ready(function() {
    $('a').click(function() {
        $('#menu').slideToggle();
    });
  $('#show-menu').change(function() {
      if(this.checked)
        $('#menu').slideDown();
      else
        $('#menu').slideUp();
  });
});
&#13;
@media screen and (max-width: 780px) {

    nav {
        width: 100%;
        margin: 0;
        padding: 0;
        position: relative;
        left: 0;
        display: block;
        opacity: 1.0 !important;
        filter: alpha(opacity=100); /* For IE8 and earlier */
    }

    nav ul {
        width: 100%;
        margin: 0 auto;
        padding: 0;
        display: none;
        float: none;
    }

    nav ul li {
        font-size: 1.3em;
        font-weight: normal;
        line-height: 40px;
        width: 100% !important;
        margin: 0;
        padding: 0;
    }

    nav ul li:nth-of-type(1) { margin-top: 20%; }

    nav ul li:hover { background: #565758; }
    
    nav ul li a {
        color: white !important;
        font-family: "Lato", sans-serif;
        border-bottom: none !important;
        display: inline-block;
    }

    nav ul li a.active-link {
        color: white !important;
        font-size: 1.3em;
    }

    nav ul li a:hover {
        color: white;
        width: 100%;
    }
        
    /*Display 'show menu' link*/
    .show-menu {
        margin: 0 !important;
        padding: 1em !important;
        text-align: right;
        display: block;
        float: right;
    }

    /*Show menu when invisible checkbox is checked*/
    input[type=checkbox]:checked ~ #menu { background-color: #747475 !important; display: block; height: 100vh; }
}​
&#13;
&#13;
&#13;