我有一個滾動的單頁網站,有一些問題。漢堡菜單必須點擊兩次才能展開。我不是很熟悉javascript,但想知道是否可以將某些東西添加到我現有的javascript中來解決問題。漢堡按鈕必須點擊兩次以展開
\t $(document).ready(function() {
\t \t $('a').click(function() {
\t \t \t $('#menu').slideToggle();
\t \t });
\t $('#show-menu').change(function() {
\t \t if(this.checked)
\t \t \t $('#menu').slideDown();
\t \t else
\t \t \t $('#menu').slideUp();
\t \t });
\t }); \t \t
@media screen and (max-width: 780px) {
\t nav {
\t \t width: 100%;
\t \t margin: 0;
\t \t padding: 0;
\t \t position: relative;
\t \t left: 0;
\t \t display: block;
\t \t opacity: 1.0 !important;
\t \t filter: alpha(opacity=100); /* For IE8 and earlier */ }
\t /*Make dropdown links appear inline*/
\t nav ul {
\t \t width: 100%;
\t \t margin: 0 auto;
\t \t padding: 0;
\t \t display: none;
\t \t float: none; }
\t /*Create vertical spacing*/
\t nav ul li {
\t \t font-size: 1.3em;
\t \t font-weight: normal;
\t \t line-height: 40px;
\t \t width: 100% !important;
\t \t margin: 0;
\t \t padding: 0; }
\t nav ul li:nth-of-type(1) { margin-top: 20%; }
\t nav ul li:hover { background: #565758; }
\t
\t /*Style that thing pretty*/
\t nav ul li a {
\t \t color: white !important;
\t \t font-family: "Lato", sans-serif;
\t \t border-bottom: none !important;
\t \t display: inline-block; }
\t nav ul li a.active-link {
\t \t color: white !important;
\t \t font-size: 1.3em; }
\t nav ul li a:hover {
\t \t color: white;
\t \t width: 100%; }
\t \t
\t /*Display 'show menu' link*/
\t .show-menu {
\t \t margin: 0 !important;
\t \t padding: 1em !important;
\t \t text-align: right;
\t \t display: block;
\t \t float: right; }
\t /*Show menu when invisible checkbox is checked*/
\t \t input[type=checkbox]:checked ~ #menu { background-color: #747475 !important; display: block; height: 100vh; }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
\t <nav>
\t <label for="show-menu" class="show-menu"><img src="hamburger.png" alt="Hamburger Menu Icon" style="width: 15%;"></label>
\t <input type="checkbox" id="show-menu" role="button">
\t \t <ul id="menu" class="open">
\t \t <li><a href="#choco">HOME</a></li>
\t \t <li><a href="#about-page">ABOUT</a></li>
\t \t <li><a href="#portfolio-page">PORTFOLIO</a></li>
\t \t <li><a href="#contact.html">CONTACT</a></li>
\t \t </ul>
\t </nav>
似乎爲我工作的罰款。 –
你點擊兩次是什麼意思?像雙擊或3部分切換? – Skylark
對我來說也很好 – Steve