JavaScript的解決方案,我正在尋找應做到以下幾點:選擇錨點鏈接時強制關閉屏幕切換菜單?
撥動開屏外切換菜單
選擇一個錨標記的菜單鏈接,導航到
在同一頁上的錨定段的切換菜單關閉
這是一個完整的代碼Fidd樂演示該問題:https://jsfiddle.net/fpbs6fkz/
注:其它JS + CSS太長張貼在堆棧溢出**
有問題的JavaScript的:
// Find all menu links
var navLinks = document.querySelectorAll('.c-menu__link');
// For each menu link
var index = 0, length = navLinks.length;
for (; index < length; index++) {
// Attach click event, on click call close function
navLinks[index].addEventListener('click',
function() {
slideLeft.close();
}
);
}
以上是JavaScript每當我點擊錨點鏈接並導航到期望部分時,應該關閉切換菜單的功能,但它根本不起作用。
HTML:
<!-- Start of Slidesmenu -->
<div class="mobilemenu">
<div class="wsmenucontent overlapblackbg"></div>
<div class="wsmenuexpandermain slideRight">
<a id="navToggle" class="animated-arrow slideLeft"><span></span></a>
<a href="#" class="smallogo"><img src="assets/img/logo4.png" width="120" style= "margin-top:-5px;" alt="" /></a>
</div>
<nav id="c-menu--slide-left" class="wsmenu slideLeft">
<ul class="mobile-sub wsmenu-list">
<li class="c-menu__item"><a href="#about" class="c-menu__link active"><i class="fa fa-home"></i>About</a></li>
<li class="c-menu__item"><a href="#contact" class="c-menu__link"><i class="fa fa-road"></i>Contatc</a></li>
<li class="c-menu__item"><a href="#fhowitworks" class="c-menu__link"><i class="fa fa-flask"></i>How it Works</a></li>
<li class="c-menu__item"><a href="#tools" class="c-menu__link"><i class="fa fa-puzzle-piece"></i>Tools</a></li>
<li class="c-menu__item"><a href="#help" class="c-menu__link"><i class="fa fa-wrench"></i>Help</a></li>
<li class="c-menu__item"><a href="#customers" class="c-menu__link"><i class="fa fa-server"></i>Customers</a></li>
<li class="c-menu__item"><a href="#business" class="c-menu__link"><i class="fa fa-lock"></i>Business</a></li>
<li class="c-menu__item"><a href="#location" class="c-menu__link"><i class="fa fa-users"></i>Location</a></li>
<li class="c-menu__item"><a href="contact.html" class="c-menu__link"><i class="fa fa-envelope-o"></i>Contact</a></li>
</ul>
</nav>
</div>
<div id="about"><p>About</p></div>
<div id="contact"><p>Contact</p></div>
<div id="howitworks"><p>How it Works</p></div>
<div id="tools"><p>Tools</p></div>
<div id="help"><p>Help</p></div>
<div id="customers"><p>Customers</p></div>
<div id="business"><p>Business</p></div>
<div id="location"><p>Location</p></div>
<script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-1.11.2.min.js"><\/script>')</script>
所以我的問題是:
如何解決的JavaScript代碼,以便切換菜單關閉,並導航到錨固段當我選擇一個錨菜單鏈接?
能你指定你使用的插件的名稱(菜單) –
它沒有插件,只有jquery 1.1.2分鐘。檢查小提琴。代碼是所有https://jsfiddle.net/fpbs6fkz/ – ChosenJuan
好吧,但我看不到'slideLeft'在這裏定義。和什麼是你調用的'.close()'方法 –